1👍
✅
I solved this issue using two filters:
template.py:
{% load my_tags %}
{%for obj in objs%}
{%for key in obj|get_dict %}
{% with d=obj|get_dict %}
{{key}} - {{ d|get_val:key }}
{% endwith %}
{%endfor%}
{%endfor%}
my_tags.py:
@register.filter(name='get_dict')
def get_dict(v):
return v.__dict__
@register.filter(name='get_val')
def get_val(value, arg):
return value[arg]
👤mrbf
0👍
Must be honest, I’m not sure about the properties of a RawQuerySet
. If it was a normal QuerySet
, I’d try this.
{% for obj in objs.values %}
{% for key, val in values.items %}
{{ key }}: {{ val }}
{% endfor %}
{% endfor %}
Does that do the trick?
- [Answer]-Override save vs Custom field in Django
- [Answer]-How to perform a specific task in django automatically after a fixed interval of time?
- [Answer]-Nested block inside if condition django
- [Answer]-Django OAuth Toolkit protected_resource for class-based views
Source:stackexchange.com