Django - How to increment integer field from user input?

前端 未结 2 557
长发绾君心
长发绾君心 2020-12-13 04:24

I\'m new to Django, but I\'m building a website where people can make statements regarding certain debatable topics. Right now I\'ve just manually added a few statements for

2条回答
  •  清歌不尽
    2020-12-13 05:03

    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)
    

提交回复
热议问题