Search code examples
pythondjangoinline-formset

How can I use only one set of fields when i use an inline_formset?


I'm a bit of Django noob, and I have this problem:

I have an inline_formset, but when I'm going to use it in my template, it shows me 3 sets of fields. This is my inline_formset:

StorageFormSet = inlineformset_factory(WorkOrder, Storage, fields=('sto_type', 'paper_type', 'paper_qnty', 
'web_paper_qnty',))

And this is my template:

{% for field in storage_formset %}
    {{ storage_formset.management_form }}
    {{ field.errors }}
    {{ field.help_text }}
    {{ field }}
    {% endfor %}

I only need 1 set of fields, because I'm planning to use "django-dynamic-formset" in case I need more than one, and i don't understand how can i fix this.

I've tried this:

{% for field in storage_formset %}
    {{ storage_formset.management_form }}
    {{ field.errors }}
    {{ field.help_text }}
    {{ field.sto_type }}
    {% endfor %}

But then i get 3 fields for "sto_type"

If you can help me, thank you :)


Solution

  • Set the extra argument of the function to 1:

    StorageFormSet = inlineformset_factory(WorkOrder, Storage,
                                           fields=('sto_type', 'paper_type',
                                                   'paper_qnty', 'web_paper_qnty',),
                                           extra=1)