作者:NarratorWang | 来源:互联网 | 2023-05-17 12:16
IhaveatablewithanIntegerField(hit_count),andwhenapageisvisited(forexample,http:sit
I have a table with an IntegerField
(hit_count
), and when a page is visited (for example, http://site/page/3
) I want record ID 3's hit_count
column in the database to increment by 1.
我有一个包含IntegerField (hit_count)的表,当访问一个页面(例如,http://site/page/3)时,我希望记录ID 3在数据库中的hit_count列增加1。
The query should be like:
查询应如下:
update table set hit_count = hit_count + 1 where id = 3
Can I do this with the standard Django Model conventions? Or should I just write the query by hand?
我可以使用标准的Django模型约定吗?还是我应该手工编写查询?
4 个解决方案