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)
保健佳品錯誤 – 2013-03-28 10:14:21