你这是免费的:
http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects
默认情况下,您可以访问管理器,该管理器允许您通过RELATEDCLASSNAME_set
属性访问相关项:
some_foo.bar_set.all()
或者您可以使用related_name
参数来ForeignKey
指定应该保存反向关系Manager的属性:
class Foo(models.Model): name = models.CharField() class Bar(models.Model): title = models.CharField() foo = models.ForeignKey(Foo, related_name='bars') ... some_foo.bars.all()