我有 3 个模型(简化):
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)
每次我保存提款时,我必须做:
client.PersonalAccount.balance = client.PersonalAccount.balance - withdrawal.amount
client.PersonalAccount.save
我应该使用什么信号来做到这一点?pre_save
,post_save
还是init
那些?我想让调试变得容易。如果任何账户操作失败,它不应该保存提款。我也完全不确定我的关系语法是否正确,所以如果有人冷淡地澄清这一点..