Separator between forms in formset factory

137 views
Skip to first unread message

Jeroen van Oorschot

unread,
Jan 28, 2017, 9:08:00 AM1/28/17
to Django users
Hi,
I'm using a
modelformset_factory()

for displaying a form multiple times automatically. This works perfect.

I would like to have some kind of separator between the individual forms in the page. Now the formsetfactory just shows all forms after eachother, and it can be quite hard too see which input belongs to which form.

Does anyone have an idea how to make this? If not, i'd like to request it as a feature on the formset_factory.

Kind regards,
Jeroen
formsetfactory.png

Michal Petrucha

unread,
Jan 28, 2017, 11:37:53 AM1/28/17
to Django users
> <https://docs.djangoproject.com/en/1.10/_modules/django/forms/formsets/#formset_factory>
> .
>
> Kind regards,
> Jeroen

Hi Jeroen,

Have you considered simply iterating over the individual forms in your
template, and including the separator in the for loop? You can find
some examples in the docs [1].

Good luck,

Michal


[1]: https://docs.djangoproject.com/en/1.10/topics/forms/formsets/#using-a-formset-in-views-and-templates
signature.asc

Grzegorz Tężycki

unread,
Jan 28, 2017, 2:55:59 PM1/28/17
to Django users
How you render your formset.
You can add separator in your html template:

example:
{% for form in formset.forms %}
   
{{ form.as_p }}
   
{% if not forloop.last %}
       
<hr/>
   
{% endif %}
{% endfor %}

Jeroen van Oorschot

unread,
Jan 30, 2017, 6:54:02 AM1/30/17
to Django users
Thanks for the tip, this works fine indeed.
I expected it to be some option on the formset, but this is ok as well.
Reply all
Reply to author
Forward
0 new messages