assume I have this little model:
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)
when I try to use this increase_purchases model from shell:
>>> x = Deal.objects.get(id=1)
>>> x.increase_purchases(4)
AttributeError: 'Deal' object has no attribute 'update'
How can I write a proper function to the model so that I can update the selected querys purchases as I want ?
Based on your example and description, you probably want something like this:
I agree with Ignacio; modify the object and then save it. So in the shell:
Yes, I renamed things a little bit in the Deal model. It just seemed more descriptive this way.