0
我想通過使用過濾條件的外鍵獲取記錄集。但不知何故,這是行不通的。我在這裏展示的模型:通過ForeignKey過濾Django QuerySet
class MessageMonitoring(models.Model):
MyID = models.ForeignKey(AboutMe, null=True, blank=True, related_name='MessageMonitor')
class AboutMe(models.Model):
MyGender = models.CharField(max_length=50, choices = GENDER_CHOICES)
在我看來,我想做到以下幾點:
recipient = AboutMe.objects.get(pk=toid)
monitor_recip = MessageMonitoring.objects.filter(MessageMonitor_owner=recipient)
,但我得到了以下錯誤:
Cannot resolve keyword 'MessageMonitor_owner' into field. Choices are: MyID, ...
謝謝。我已經忘記了這一點! – disruptive