Add comment to vote
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michal Kunc 2023-01-24 21:37:57 +01:00
parent 6ae7bed38d
commit 6a3eacbc4a
3 changed files with 11 additions and 1 deletions

View File

@ -11,7 +11,7 @@
<p>Total score: {{ movie.score }}, seen by: {{ movie.seen_score }}.
<ul>
{% for vote in votes %}
<li>{{vote.user.username}} {% if vote.seen %}(seen){% endif %} &ndash; {% if vote.vote == 1 %}👍{% elif vote.vote == 0 %}No opinion{% elif vote.vote == -1 %}👎{%endif%}</li>
<li>{{vote.user.username}} {% if vote.seen %}(seen){% endif %} &ndash; {% if vote.vote == 1 %}👍{% elif vote.vote == 0 %}No opinion{% elif vote.vote == -1 %}👎{%endif%}{% if vote.comment is not None %} &ndash; {{vote.comment}}{% endif %}</li>
{% endfor %}
</ul>
{% endif %}
@ -30,6 +30,10 @@
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="seen" name="seen" {% if user_vote and user_vote.seen %} checked {%endif%}><label class="form-check-label" for="seen">I saw this movie already</label><br>
</div>
<div>
<label class="form-check-label" for="comment">Comment</label>
<input class="form-control" type="text" id="comment" name="comment" {% if user_vote and user_vote.comment %} value="{{user_vote.comment}}"{% endif %}>
</div>
<input class="btn btn-primary" type="submit" value="Submit">
</form>

View File

@ -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}"

View File

@ -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'))