1

私はこのpythonドライバーを使用しています。ORMを使用して正しい方法でカウンターをインクリメントするにはどうすればよいですか?

たぶん、またはのようなものですupdate(counter_value__add=1)obj.counter_value += 1

この手動クエリを回避しようとしていますUPDATE ... SET counter_value = counter_value + 1

4

1 に答える 1

2

Resolved issue which tell, that correct way is obj.counter_value += 1 But its deprecated!

Right way is:

CounterModel(pk=pk, ck=ck).update(counter_field=1, another_counter=-2)

Also you can use update method of counter model object.

P.S.

  • There is no need to create counters, They are 0 by default.
  • You cant create counter row via .create() method.
  • You cant set any value to counter directly.
于 2016-06-09T09:38:27.240 に答える