如果通过获取查询集中的第一个对象属性来访问,Django 对象的属性将变为字符串
我有一个问题,如果我访问像 queryset.0.attr1 这样的查询集中的对象属性,它会丢失它的类型并变成一个字符串(Django 模板处理器像字符串一样处理它)
简单的例子:我有一个查询集,它有相关的集合,但是当我通过 index.attribute_name
访问此相关集第一个对象的属性时,它变成字符串。如果我在循环中执行相同的操作 - 该属性保持其类型,
{% for p in periods %}
BECOMES STRINGS accessed via .0.attr
{{ p.productions.0.time }} str
{{ p.productions.0.amount }} str
MANTAIN TYPES accessed in a loop
{% for pp in p.productions %}
{{ pp.amount }} timedelta
{{ pp.time }} decimal
{% endfor %}{% endfor %}
我希望以某种方式使用其原始类型访问查询集中第一个对象的属性
I have a problem that if I access objects attributes in queryset like queryset.0.attr1 it looses it’s type and become a string (Django template processor processes it like a string)
Simple example: I got a queryset, that have related set, but when I access this related set first object's attribute by index.attribute_name
it becomes string. If I do the same thing in a loop - this attribute maintain its type
{% for p in periods %}
BECOMES STRINGS accessed via .0.attr
{{ p.productions.0.time }} str
{{ p.productions.0.amount }} str
MANTAIN TYPES accessed in a loop
{% for pp in p.productions %}
{{ pp.amount }} timedelta
{{ pp.time }} decimal
{% endfor %}{% endfor %}
I want somehow to access attributes of first object in queryset with it’s original type
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我应该重新启动服务,现在一切都很好
I should just restart service, everything is fine now