def watch(request, poll_url):
current_poll = get_object_or_404(Poll, url=poll_url)
if not current_poll.can_watch(request.user, request):
messages.error(
request, _("You are not allowed to watch this poll.")
)
return redirect('poll', poll_url)
if current_poll.user_watches(request.user):
poll_watch = PollWatch.objects.get(poll=current_poll, user=request.user)
poll_watch.delete()
else:
poll_watch = PollWatch(poll=current_poll, user=request.user)
poll_watch.save()
return redirect('poll', poll_url)
评论列表
文章目录