django 1.6 中的复杂查询集
Complicated queryset in django 1.6
我正在开发 django 1.6,我想在 Season's inactive 为 True 时过滤所有 Activities
。
以下型号可以做到这一点吗?
class Production 没有 SeasonProduction 和 Season 的 ForeignKey。
class Activity(models.Model):
production = models.ForeignKey(Production, null=True, verbose_name='ProductionId')
class SeasonProduction(models.Model):
season = models.ForeignKey(Season, verbose_name='SeasonId')
production = models.ForeignKey(Production, verbose_name='ProductionId')
class Season(models.Model):
name = models.CharField('Name', max_length=255)
inactive = models.BooleanField(default=True)
class Production(models.Model):
prod_info = models.CharField('ProductionInfo', max_length=255,
null=True, blank=True)
title = models.CharField('Title', max_length=255)
试试这个:
season_prods = SeasonProduction.objects.filter(season__inactive=True)
activities = Activity.objects.filter(
production__in=season_prods.values('production_id'))
相关文档链接:
我正在开发 django 1.6,我想在 Season's inactive 为 True 时过滤所有 Activities
。
以下型号可以做到这一点吗? class Production 没有 SeasonProduction 和 Season 的 ForeignKey。
class Activity(models.Model):
production = models.ForeignKey(Production, null=True, verbose_name='ProductionId')
class SeasonProduction(models.Model):
season = models.ForeignKey(Season, verbose_name='SeasonId')
production = models.ForeignKey(Production, verbose_name='ProductionId')
class Season(models.Model):
name = models.CharField('Name', max_length=255)
inactive = models.BooleanField(default=True)
class Production(models.Model):
prod_info = models.CharField('ProductionInfo', max_length=255,
null=True, blank=True)
title = models.CharField('Title', max_length=255)
试试这个:
season_prods = SeasonProduction.objects.filter(season__inactive=True)
activities = Activity.objects.filter(
production__in=season_prods.values('production_id'))
相关文档链接: