2011-03-09 60 views
1
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 = 945678987Person.employer = 'xyz'Django的 - 加入2種型號在查詢

回答

4
Phone.objects.filter(number='945678987', person__employer='xyz')