django模型查询返回参考过滤器混淆

时间:2012-03-14 01:51:54

标签: django model

鉴于以下模型

class Category(models.Model):
  name = models.CharField(max_length=50)

class Business(models.Model):
  name = models.CharField(max_length=50)
  category = models.ForeignKey(Category, related_name="businesses")

class Package(models.Model):
  business_id = models.ForeignKey(Business)
  status = models.CharField(max_length=50)

我有2个以下查询获取包裹所在的业务和类别列表:

filter_businesses = Business.objects.filter(package__status = 'live')
filter_categories = Category.objects.filter(businesses__package__status = 'live')

现在的问题是,鉴于相关名称“business”应该等于category.business_set,为什么第一个查询中的过滤器不应该是package_set?

0 个答案:

没有答案