以为我这个小模型:Django的,从模型更新
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)
,当我尝试使用这个从壳increase_purchases型号:
>>> x = Deal.objects.get(id=1)
>>> x.increase_purchases(4)
AttributeError: 'Deal' object has no attribute 'update'
我如何写一个适当的功能模型以便我可以根据需要更新所选查询的购买情况?
但据我所知保存将保存一个新的实例,而我想更新现有的。视为 – Hellnar 2010-02-09 05:53:05
如果PK为“无”或数据库中不存在,它将仅创建一条新记录。否则它会用上述PK更新现有记录。 – 2010-02-09 05:55:07