假设我有这个小模型:
class Deal(models.Model):
purchases = models.IntegerField(default=0)#amount of purchases so far
increase_purchases(self,to_add):
self.update( purchases =self.purchases + to_add)
当我尝试从 shell 使用这个 increase_purchases 模型时:
>>> x = Deal.objects.get(id=1)
>>> x.increase_purchases(4)
AttributeError: 'Deal' object has no attribute 'update'
如何为模型编写适当的函数,以便可以根据需要更新选定的查询购买?