Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def votes_total(request):
- total = Vote.objects.all().count()
- total_true = Vote.objects.filter(answer__exact=True).count()
- total_false = Vote.objects.filter(answer__exact=False).count()
- context = {
- 'total': total,
- 'total_true': total_true,
- 'total_false': total_false
- }
- return render(request, 'student\index.html', context)
- def votes_action(request, action):
- total = Vote.objects.all().count()
- total_true = Vote.objects.filter(answer__exact=True).count()
- total_false = Vote.objects.filter(answer__exact=False).count()
- context = {
- 'total': total,
- 'total_true': total_true,
- 'total_false': total_false
- }
- if action == 'add':
- options = [True, False]
- Vote(answer=choice(options)).save()
- elif action == 'del':
- last = Vote.objects.all().count() - 1
- Vote.objects.all()[last].delete()
- return render(request, 'student\index.html', context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement