我在json中返回数据库数据有问题,这是我的代码:
模型:
class Savedrequest(models.Model):
date = models.DateTimeField(auto_now_add=True)
data1 = JSONField()
data2 = JSONField()
def __str__(self):
return self.data1, self.data2, self.date
视图:
def affiche(request):
queryset= Savedrequest.objects.all()
datajson= list(queryset)
context = {
"object_list":datajson,
}
return render(request,"affiche.html" ,context)
HTML:
{% for obj in object_list %}
{{obj.date}}
<textarea id="txth" class='txtarea' style="display:;" >{{obj.data1.result}}</textarea>
<textarea id="txtv" class='txtarea' style="display:;" >{{obj.data2.result}}</textarea>
{% endfor %}
我想要的回归json是:
[{u'luns': [{u'host_cluster_id': 0, u'volume_id': 1012, u'clustered': False, u'host_id': 1006, u'id': 1, u'lun': 1}, {u'host_cluster_id': 0, u'volume_id': 1016, u'clustered': False, u'host_id': 1006, u'id': 2, u'lun': 2}]'