From 6a3eacbc4af269f1f3580080f461eb53d904de5a Mon Sep 17 00:00:00 2001 From: Michal Kunc Date: Tue, 24 Jan 2023 21:37:57 +0100 Subject: [PATCH] Add comment to vote --- templates/watchlist/movie_detail.html | 6 +++++- watchlist/models.py | 1 + watchlist/views.py | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/templates/watchlist/movie_detail.html b/templates/watchlist/movie_detail.html index 8883d69..19cca4d 100644 --- a/templates/watchlist/movie_detail.html +++ b/templates/watchlist/movie_detail.html @@ -11,7 +11,7 @@

Total score: {{ movie.score }}, seen by: {{ movie.seen_score }}.

{% endif %} @@ -30,6 +30,10 @@

+
+
+ +
diff --git a/watchlist/models.py b/watchlist/models.py index 6c24abd..12818fe 100644 --- a/watchlist/models.py +++ b/watchlist/models.py @@ -36,6 +36,7 @@ class MovieVote(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) vote = models.IntegerField(choices=Vote.choices, default=Vote.NOVOTE) seen = models.BooleanField(default=False, null=True) + comment = models.TextField(null=True) def __str__(self): return f"{self.user.username}'s vote for {self.movie.name}" diff --git a/watchlist/views.py b/watchlist/views.py index daf2266..d2bc4df 100644 --- a/watchlist/views.py +++ b/watchlist/views.py @@ -69,6 +69,11 @@ def vote(request, pk): user_vote = models.MovieVote(movie=movie, user=request.user) user_vote.vote = request.POST['vote'] user_vote.seen = request.POST.get('seen', False) == "on" + comment = request.POST.get('comment', '').strip() + if comment != '' or user_vote.comment is not None: + if comment == '': + comment = None + user_vote.comment = comment user_vote.save() return HttpResponseRedirect(reverse('watchlist:index'))