django - django 嵌套查询过滤
问题描述
我有嵌套模型。像这些:
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 的项目,而不是全部。我应该怎么办?有什么方法可以在项目列表中获取特殊项目而不是全部
解决方案
推荐阅读
- python - Python Selenium 无法访问 Tableau 小部件
- javascript - 如何使用 JavaScript 将名称列表与相关数据项列表中的聚合数据值映射?
- amazon-web-services - AWS API Gateway 403 Forbidden response OPTIONS
- ssis - BIML 类块错误:“AstTableNode”不包含“GetTag”的定义,并且没有可访问的扩展方法“GetTag”
- c# - 如何针对旧版本的库运行 .NET 核心应用程序
- python - 使用 python 从 bigquery 调用外部表
- networking - 当 VPN 在 WSL2 中打开时,如何从 WSL2 ping 窗口
- android - 使用相机2。当我调用 closeCamera 时,显示最后看到的帧而不是黑屏
- elasticsearch - 即使在设置 request_cache=true 之后,我也没有看到代价高昂的 ES 查询的性能提升
- python-3.x - 如何从 html 报告中删除跳过的测试