2017-02-23 75 views
0

我正在研究django 1.6,並且我想在Season的非活動狀態爲True時過濾所有Activitiesdjango 1.6中的複雜查詢集

這對於以下模型是可能的嗎? 班生產沒有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) 
+0

我可以問你爲什麼要使用Django 1.6。它已經過時和越野車了。 –

+0

Becasue項目在django 1.6 @gitblame – mark

+0

你可以發佈'Production'模型定義嗎? –

回答

0

試試這個:

season_prods = SeasonProduction.objects.filter(season__inactive=True) 

activities = Activity.objects.filter(
    production__in=season_prods.values('production_id')) 

相關的文檔鏈接:

+0

非常感謝! :) – mark