我想要获取main_contact.paid=True
所有的Runner记录。我不能训练Django的电话。
以下是模型:
class Main_contact(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
email = models.EmailField()
tel = models.CharField(max_length=20)
token = models.CharField(max_length=255)
paid = models.BooleanField(default=False)
class Runner(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
age = models.IntegerField(default=0)
fee = models.IntegerField(default=0)
main_contact = models.ForeignKey(Main_contact)
答案 0 :(得分:1)
尝试遍历以下关系:
Runner.objects.filter(main_contact__paid=True)