daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Apr 25th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def votes_total(request):
  2.     total = Vote.objects.all().count()
  3.     total_true = Vote.objects.filter(answer__exact=True).count()
  4.     total_false = Vote.objects.filter(answer__exact=False).count()
  5.     context = {
  6.         'total': total,
  7.         'total_true': total_true,
  8.         'total_false': total_false
  9.     }
  10.     return render(request, 'student\index.html', context)
  11.  
  12. def votes_action(request, action):
  13.     total = Vote.objects.all().count()
  14.     total_true = Vote.objects.filter(answer__exact=True).count()
  15.     total_false = Vote.objects.filter(answer__exact=False).count()
  16.     context = {
  17.         'total': total,
  18.         'total_true': total_true,
  19.         'total_false': total_false
  20.     }
  21.     if action == 'add':
  22.         options = [True, False]
  23.         Vote(answer=choice(options)).save()
  24.     elif action == 'del':
  25.         last = Vote.objects.all().count() - 1
  26.         Vote.objects.all()[last].delete()
  27.     return render(request, 'student\index.html', context)
RAW Paste Data
Top