0

我有一个经理 (AccountManager),我想过滤 FK 用户,但该用户链接在帐户表中。我尝试了以下方法.filter(account.user=user),但这给了我一个错误。

这样做的正确方法是什么?下面的代码。

谢谢

class AccountManager(models.Manager):
    def for_user(self, user):
        return self.get_query_set().filter(account.user=user)

class Transaction(models.Model):

    account = models.ForeignKey('Account',
                                related_name='transactions')

    amount = models.DecimalField(max_digits=10, decimal_places=1)
    objects = AccountManager()


class Account(models.Model):


    OPEN, FROZEN, CLOSED = 'Open', 'Frozen', 'Closed'
    status = models.CharField(max_length=32, default=OPEN)
    #FK
    user = models.OneToOneField(User)
4

1 回答 1

1
class AccountManager(models.Manager):
    def for_user(self, user):
        return self.get_query_set().filter(account__user=user)
于 2013-03-28T10:20:39.823 回答