8

如果我有以下表格

class Town(models.Model):
    created = models.DateTimeField()

class Street(models.Model):
    town = models.ForeignKey(Town)
    created = models.DateTimeField()

class House(models.Model):
    street = models.ForeignKey(Street)
    created = models.DateTimeField()

如果我有城镇的名称/id,如何获得Housea 中的所有 s ?Town

4

1 回答 1

16

这应该可以解决问题:

town_id = 5
houses_in_town = House.objects.filter(street__town__id = town_id)
于 2013-03-21T16:39:07.593 回答