AlexBrand
AlexBrand

Reputation: 12399

django - displaying a single field from inline formset

I was trying to only display a single field from an inline formset, but the field won't show up:

In the template:

{{ formset.phone_number }}

What am I doing wrong?

Upvotes: 0

Views: 354

Answers (1)

jpic
jpic

Reputation: 33420

Iterate over forms in the formset:

{% for form in formset %}
    {{ form.phone_number }}
{% endfor %}

See documentation on formsets:

The formset gives you the ability to iterate over the forms in the formset and display them as you would with a regular form:

>>> formset = ArticleFormSet()
>>> for form in formset:
...     print(form.as_table())

Upvotes: 1

Related Questions