Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在我的模型上添加了一个计数字段,以便我可以在用户单击特定按钮时进行计数。但是,每次单击按钮时,我的 SmallIntegerField 似乎都会加倍。
有什么提示吗?
模型:
applicant_count = models.SmallIntegerField(_('Applicant Count'))
看法:
job.applicant_count = F('applicant_count')+1 job.save()
非常感激!
为什么要使用F()表达式?那是为了引用查询中的字段。尝试:
F()
job.applicant_count = job.applicant_count + 1 job.save()