68
kyiphyu’s code can be further simplified using F expressions:
from django.db.models import F
Statement.objects.filter(id__in=statements).update(vote=F('vote') + 1)
-3
You can get the user input with
statements = request.POST.getlist('statement')
From that list, you can increase the vote count and update database like
for st in statements:
statement = Statement.objects.get(id=st)
statement.vote += 1
statement.save()
Hope this helps you.
- [Django]-Is it secure to store passwords as environment variables (rather than as plain text) in config files?
- [Django]-Sqlite3.OperationalError: unable to open database file
- [Django]-Get javascript variable's value in Django url template tag
Source:stackexchange.com