context = { 'sof': sof })
Is it not possible to access meta data in templates ?
{% for field in sof.so._meta.fields %}
<div>
<dt>{{ field.verbose_name }}</dt>
<dd>{{ field.value }}</dd>
</div>
{% endfor %}
context = { 'sof': sof })
Is it not possible to access meta data in templates ?
{% for field in sof.so._meta.fields %}
<div>
<dt>{{ field.verbose_name }}</dt>
<dd>{{ field.value }}</dd>
</div>
{% endfor %}
I don’t see why not.
What is the sof
being passed in the context?
I think Django complains about it.
TemplateSyntaxError: Variables and attributes may not begin with underscores
sof is a result of a ORM get() query.
you can provide meta data like:
context = {'meta_fields': obj._meta.fields}
but, why need meta data in template??
For example to use verbose_name
as labels.
i think use modelform will be better.
# views.py
context = {'form': {ModelForm object}}
# template
{% for field in form %}
{{ field.label }}
{{ field.initial }}
{% endfor %}