Answer the question
In order to leave comments, you need to log in
Django F+update not updating a field?
Django 1.8, postgre base.
There is a Wallet model with a balance field, and there is a method that updates it
def update_balance(self, amount):
Wallet.objects.filter(pk=self.pk).update(balance=models.F("balance")+amount)
return
def test_change_wallet_balance(self):
amount = 5000
self.wallet.update_balance(amount)
self.assertEqual(self.wallet.balance, 15000)
Answer the question
In order to leave comments, you need to log in
You need this https://docs.djangoproject.com/en/1.8/ref/models/i...
You have an instance of the model (representation in the form of a python object of the record from the database), when you do an update, you update the data in the database itself, while the model instance was what it was and remained.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question