I got 3 models (simplifying):
class User(models.Model):
...
class PersonalAccount(models.Model):
user = models.OneToOneField(user)
balance = MoneyField() (like float)
class Withdrawal(models.Model):
date = models.DateField()
amount = MoneyField()
client = ForeignKey(User)
account =ForeignKey(PersonalAccount)
Every time I save the Withdrawal I must do:
client.PersonalAccount.balance = client.PersonalAccount.balance - withdrawal.amount
client.PersonalAccount.save
What signal should I use to do it? pre_save
, post_save
or init
ones? I want to make it easy to debug. It should not save Withdrawal if any of account operations fail.
I'm also totally not sure I got relation syntax right so if someone cold clarify on this..