From dec867b3649d97ba2a076614a8e18478b759c864 Mon Sep 17 00:00:00 2001 From: gkuer Date: Mon, 22 Nov 2021 01:05:41 +0900 Subject: [PATCH] stisfied-docket Former-commit-id: c45180e212dc7c5dfe68e47c88845a6631ed3072 --- db.sqlite3 | Bin 315392 -> 315392 bytes movies/migrations/0009_auto_20211122_0042.py | 47 +++++++++++++++++++ movies/models.py | 7 +++ movies/templates/movies/detail.html | 31 +----------- movies/views.py | 41 ++++++++++++++-- 5 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 movies/migrations/0009_auto_20211122_0042.py diff --git a/db.sqlite3 b/db.sqlite3 index 756b1aebb035ff75ebc275a15e85f269919e9743..fc3fcd457280611bc069b121eb93e85e7ed45f18 100644 GIT binary patch delta 7167 zcmbVR4RjROb$&myzq7j|2?>FXU?qh4U(L_X?5;3B3stZ&2=QlJEF%jcKoqn>h8nw0 zmjywcnAF4)8OOmcP-@pFI2I9RZDi!cF{x>tl*Bl84^C^J(_bXnIVbVyIZaQ~``%lS zv>CA{*0Ar+ym|L~_rCAmJ8y;qCnp>@IpNry#U~L$tKjE_AA#T3zB$jpC(k{6Mxhnn zce*`A3F3XHFIjZZyXfu;7n-~vxjXfzZLN=}s+wqO-nTc^q^r87X}aE|s!^R?%-6K} zx)#>V+NfTu>ycQ@Fje)h$z)I1hXSFOyh^|FAId@HtnwA*q0kRP!%8ajl469eg--WX zss}=z&^0vGTYhKv)S8KRkm3?LgNQksT2i}Go#-b@`7~;J?cNkA?H-OyS+6{Y=HT3r z&Q`GQ(LhlJo#`9X1%oE}ilKY#NK)pZ^U2no&F$M$P0d?(x3xFzN^M6Ubw5;Z?EfGCul+;*fAjyd z|3m*(<+%Kwd|4ilvvRNevV2<^A#=d8gbWH_992dU?6LL{7-MJXfxk zE98l?B75y6y|^m7`4s-dn|4!7eCQ(~J`~~?LVO^^H6h*?;^#vAj0r!wD#Sku@lzpw zBE)+_{DTmGFT@olWc02Of9Fo~%O8u&%R;;(#E*n{TZkVD@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P18X63Mg@Xpt9uy0B+d>{8(Qz<_^a_wn#hAW7 z6J7P)O#4bM_dwP{o)*&U`0888TlUcOl1cpDBpSyt&z#&_<8@HbLh43{{Zg2tPcPH 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)