我需要使用id
转换这样的响应,其中Mymodel
来自模型Total_login_hours
而class Mymodel(models.Model):
status = models.CharField(max_length=50, choices=BIKER_STATUS_CHOICES, default='active')
name = models.CharField(verbose_name=_('Biker Name'), max_length=254)
classLoginModel(models.Model):
biker = models.ForeignKey(Mymodel, db_index=True, on_delete=models.PROTECT)
total_loginhrs = models.TimeField(null=True, blank=True)
来自模型
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 128,
"totaldata": [
{
"City": "abc",
"Locality ": "def",
"Biker_name": "xyz",
"Total_login_hours": "00:28:41",
"Date": "2018-01-13",
"Sublocality": "qwe"
},
{
"City": "asd",
"Locality ": "fgh",
"Biker_name": "zxc",
"Total_login_hours": "00:02:33",
"Date": "2018-01-14",
"Sublocality": "cvb"
}
]
}
]
}
我在django rest框架中使用django serializer得到如下所示的响应:
id
如何重复{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"id": 128,
"totaldata": [
{
"City": "abc",
"Locality ": "def",
"Biker_name": "xyz",
"Total_login_hours": "00:28:41",
"Date": "2018-01-13",
"Sublocality": "qwe"
}],
"id": 128,
"totaldata": [
{
"City": "asd",
"Locality ": "fgh",
"Biker_name": "zxc",
"Total_login_hours": "00:02:33",
"Date": "2018-01-14",
"Sublocality": "cvb"
}
]
}
]
}
以获得下面显示的响应?
Order