Django嵌套查询过滤

时间:2019-06-08 05:37:19

标签: django postgresql django-queryset

我有嵌套模型。像这样:

class Items_Relation_Income_Statement(models.Model):
    statement = models.ForeignKey('Items_Income_Statement', related_name="items" ,on_delete = models.CASCADE )  
    item = models.ForeignKey('Income_Statement' ,on_delete = models.CASCADE ) 
    amount = models.BigIntegerField()

class Items_Income_Statement(models.Model):
    statement_id = models.BigIntegerField(primary_key=True)
    com_id = models.IntegerField()
    bourse_symbol = models.CharField(max_length= 100, null=True, blank=True)
    full_title = models.CharField(max_length= 100, null=True, blank=True)
    period_type = models.IntegerField()
    fiscal_year_end = models.CharField(max_length= 100, null=True, blank=True)
    jalali_fiscal_year_end = models.CharField(max_length= 100, null=True, blank=True)
    period_end = models.CharField(max_length= 100, null=True, blank=True)
    jalali_period_end = models.CharField(max_length= 100, null=True, blank=True)
    anouncement_date = models.CharField(max_length= 100, null=True, blank=True)
    jalali_anouncement_date = models.CharField(max_length= 100, null=True, blank=True)
    audited = models.BooleanField()
    represented = models.BooleanField()
    consolidated = models.BooleanField()

,查询字符串的结果如下:

 {
        "statement_id": 129928,
        "com_id": 1,
        "bourse_symbol": "rrr",
        "full_title": "ghg",
        "period_type": 12,
        "fiscal_year_end": "2012-03-19T00:00:00",
        "jalali_fiscal_year_end": "1390/12/29",
        "period_end": "2012-03-19T00:00:00",
        "jalali_period_end": "1390/12/29",
        "anouncement_date": "2013-06-11T00:00:00",
        "jalali_anouncement_date": "1392/03/21",
        "audited": true,
        "represented": true,
        "consolidated": false,
        "items": [
            {
                "id": 73,
                "amount": -272087,
                "statement": 129928,
                "item": 1
            },
            {
                "id": 74,
                "amount": -8075,
                "statement": 129928,
                "item": 5
            },
]
}

我只想拥有一些带有特殊item_id的物品,而不是全部。我该怎么办?有什么方法可以在商品列表中获取不是所有的特殊商品

0 个答案:

没有答案
相关问题