模型错误帐户对象没有属性'transactions'

时间:2013-03-23 21:11:30

标签: django django-models

我的理解这应该有用......

   def _balance(self):
        aggregates = self.transactions.aggregate(sum=Sum('amount'))
        sum = aggregates['sum']
        return D('0') if sum is None else sum

但是我收到以下错误:'帐户'对象没有属性'交易'

我在模型事务上设置了相关名称事务。请参阅下面的模型

class Account(models.Model):
    OPEN, FROZEN, CLOSED = 'Open', 'Frozen', 'Closed'
    status = models.CharField(max_length=32, default=OPEN)
    # For performance, we keep a cached balance
    balance = models.DecimalField(decimal_places=5, max_digits=10,
                                  default=D('0'), null=True)
    #FK
    user = models.OneToOneField(User)

    def _balance(self):
            aggregates = self.transactions.aggregate(sum=Sum('amount'))
            sum = aggregates['sum']
            return D('0') if sum is None else sum


class Transaction(models.Model):
    account = models.ForeignKey('Account',
                                related_name='transactions')

任何想法都是为什么我的模型功能不起作用?

谢谢。

0 个答案:

没有答案