【发布时间】:2020-08-21 08:58:32
【问题描述】:
如何在 django 中设计一个模型以将以下 JSON 值存储在单个模型中
class Bus(models.Model):
source = models.CharField(max_length=200)
destination = models.CharField(max_length=200)
type= models.CharField(max_length=200)
price=models.FloatField()
我需要接受下面的 json 才能接受并存储在同一张表中 如果我可以使用 ListField ,那么它将如何用于连接
{
"source": "delhi",
"destination": "pune",
"type": "Economy",
"price":300.0,
"Connections": [
{
"source": "lon",
"destination": "liverpool",
"type": "luxury",
},
{
"source": "banglur",
"destination": "cochin",
"type": "luxury",
}
],
}
【问题讨论】:
标签: django serialization django-rest-framework model