Increment Page Hit Count in Django

前端 未结 4 930
伪装坚强ぢ
伪装坚强ぢ 2020-12-29 08:46

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

4条回答
  •  攒了一身酷
    2020-12-29 09:03

    The model conventions won't be atomic; write it by hand:

    BEGIN
    SELECT * FROM table WHERE id=3 FOR UPDATE
    UPDATE table SET hit_count=hit_count+1 WHERE id=3
    COMMIT
    

提交回复
热议问题