class Person(models.Model):
name = models.CharField(max_length=20)
employer = models.CharField(max_length=20)
class Phone(models.Model):
person = models.ForeignKey(Person)
number = models.CharField(max_length=10)
vendor = models.CharField(max_length=20)
如何编写查询以检索Phone.number = 945678987
和Person.employer = 'xyz'
所有的电话对象?
答案 0 :(得分:9)
"Lookups that span relationships"
Phone.objects.filter(number=u'945678987', person__employer=u'xyz')
答案 1 :(得分:4)
Phone.objects.filter(number='945678987', person__employer='xyz')