【发布时间】:2022-01-17 12:50:21
【问题描述】:
我想从数据库中获取我所有的对象模型并以某种方式存储它们,我拥有的模型是:
class Device (models.Model):
patientId = models.IntegerField(unique=True)
deviceId = models.CharField(unique=True,max_length=100)
hour = models.DateTimeField()
type = models.IntegerField()
glucoseValue = models.IntegerField()
我在views.py中发送它们:
device_list = list(Device.objects.all())
context = {"filename": filename,
"deviceList": device_list,
}
在 JS 中,我设法让每个对象都像这样:
{% for item in deviceList%}
console.log( "{{item}}" );
{% endfor %}
我想要以某种方式存储这些对象,但我真的不知道如何,因为它们就像模型对象 (1) 一样。
【问题讨论】:
-
试试
{{item.patientId}}或{{item.hour}}。顺便提一句。 perentID 听起来应该是 ForeignKey。 -
我已经设法像那样访问它们,但我想存储它们,而不是显示它们。
-
google "How to send json response - django" 并且在 js 端使用
json.parse({{deviceList}})...developer.mozilla.org/de/docs/Web/JavaScript/Reference/… 比你可以使用 js 中的所有数据
标签: javascript python django