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)
How to write a query to retrieve all the Phone objects where Phone.number = 945678987
and Person.employer = 'xyz'
?
Phone.objects.filter(number=u'945678987', person__employer=u'xyz')
Phone.objects.filter(number='945678987', person__employer='xyz')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.