diff --git a/db.sqlite3 b/db.sqlite3 index 756b1ae..fc3fcd4 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/movies/migrations/0009_auto_20211122_0042.py b/movies/migrations/0009_auto_20211122_0042.py new file mode 100644 index 0000000..33a1b99 --- /dev/null +++ b/movies/migrations/0009_auto_20211122_0042.py @@ -0,0 +1,47 @@ +# Generated by Django 3.2.9 on 2021-11-21 15:42 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('movies', '0008_alter_color_movie'), + ] + + operations = [ + migrations.AddField( + model_name='moviecomment', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='moviecomment', + name='updated_at', + field=models.DateTimeField(auto_now=True), + ), + migrations.AddField( + model_name='review', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='review', + name='updated_at', + field=models.DateTimeField(auto_now=True), + ), + migrations.AddField( + model_name='reviewcomment', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='reviewcomment', + name='updated_at', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/movies/models.py b/movies/models.py index 2741d97..16d92bf 100644 --- a/movies/models.py +++ b/movies/models.py @@ -42,17 +42,24 @@ class MovieComment(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True) grade = models.IntegerField() content = models.CharField(max_length=50) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) class Review(models.Model): movie = models.ForeignKey(Movie, on_delete=models.CASCADE, related_name="reviews") title = models.CharField(max_length=50) content = models.TextField() user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) class ReviewComment(models.Model): review = models.ForeignKey(Review, on_delete=models.CASCADE, related_name="comments") content = models.CharField(max_length=50) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + class UserColorRecord(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) diff --git a/movies/templates/movies/detail.html b/movies/templates/movies/detail.html index d3fcba2..223f9b8 100644 --- a/movies/templates/movies/detail.html +++ b/movies/templates/movies/detail.html @@ -42,7 +42,7 @@

{{ movie.title }}

{{ movie.overview }}
-
평균 평점 : {{ movie.naver_grade }} 점
+
평균 평점 : {{ movie.naver_grade }} 점 / 유저 평점 : {{ user_grade }} 점
개봉일 : {{ movie.release_date }}
@@ -196,35 +196,6 @@
<{{ review.title }}>
-{% comment %} 음성인식 Modal {% endcomment %} - {% endblock content %} {% comment %} Frame Expansion Modal{% endcomment %} diff --git a/movies/views.py b/movies/views.py index 689172a..c80e921 100644 --- a/movies/views.py +++ b/movies/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render,redirect -from .models import Movie, Color, MovieComment, Review, ReviewComment, UserColorRecord +from .models import Movie, MovieComment, Review, ReviewComment, UserColorRecord from .forms import ReviewCommentForm, ReviewForm, MovieCommentForm from django.contrib.auth.decorators import login_required from django.views.decorators.http import require_POST, require_http_methods, require_safe @@ -17,19 +17,40 @@ def index(request, mode): # mode : Sort if not request.user.usercolorrecord_set.all(): return redirect('movies:choice') - movies = Movie.objects.all() + temp_movies = Movie.objects.all() # Profile Color Create colors = request.user.usercolorrecord_set.all() # Color List last_color = colors[len(colors)-1] # Picked Color colors = reversed(colors) # Color Sort(Recently) + # Exclude Already Watched Movies + movies = [] + for movie in temp_movies: + for comment in movie.comments.all(): # Exist request.user Comment + if request.user == comment.user: + break + else: + for review in movie.reviews.all(): # Exist request.user Review + if request.user == review.user: + break + else: + movies.append(movie) + res_movies = [] - # Order by TMDB_Grade + # Order by TMDB_Grade + User_Grade if mode == 2: for movie in movies: - score = movie.naver_grade + naver_score = movie.naver_grade + user_score = 0 + for comment in movie.comments.all(): + user_score += comment.grade + if user_score: + user_score = round((user_score / movie.comments.all().count()),1) * 2 + score = (naver_score + user_score) / 2 + else: + score = naver_score res_movies.append([movie, score]) # Order by Release Date @@ -112,10 +133,22 @@ def detail(request, movie_pk): last_color = colors[len(colors)-1] # Picked Color colors = reversed(colors) # Color Sort(Recently) + # User Grade + comments = movie.comments.all() + + user_grade = 0 + if comments: + for comment in comments: + user_grade += comment.grade + user_grade = 2*round(user_grade / len(comments),1) + else: + user_grade = "-" + context = { 'movie': movie, 'colors': colors, 'last_color': last_color, + 'user_grade': user_grade, } return render(request,'movies/detail.html', context)