【发布时间】:2017-08-03 13:01:42
【问题描述】:
我有如下模型结构
class BaseProduct:
id = models.CharField(max_length=15)
name = models.CharField(max_length=20)
class Product
base_product = ForeigKey(BaseProduct)
name = models.CharField(max_length=20)
class Condition:
category = models.ForeignKey(Product, related_name='allowed_product')
check = models.IntegerField(default=0)
allow = models.PositiveSmallIntegerField(default=1)
查询:
Product.objects.filter(condition__allow=1, condition__check=1)
我想要如下格式 基础产品和产品列表中基于允许和检查过滤器
[
{
"name": "BaseProduct 1",
"products": [
{
"name": "TV",
}, {}, ....
]
},
........
]
【问题讨论】:
标签: django python-2.7 django-serializer