Closed Bast66 closed 4 years ago
You can limit it by passing in factory_kwargs when creating the InlineFormSetFactory.
The 'extra': 2, is the variable you want to change.
class CampaignFilterInline(InlineFormSetFactory):
model = CampaignFilter
fields = ['filter', 'filter_type', 'filter_join']
factory_kwargs = {'extra': 2, 'max_num': None,
'can_order': False, 'can_delete': True}```
I want to render only one formset and have the option to add up to 3.
factory_kwargs = {'extra': 1, 'max_num': 3 ... }
How should I add the 2 extra formsets in the UI?
I'd recommend that you set extra=2
and use some javascript to hide/reveal the extra rows in the formset. That can get complicated when you're dealing with formsets containing errors in the extra rows though!
@sdolemelipone Thanks for answering. I keep making some research and found this article with a pretty clear step-by-step that served at least for me.
More specifically the library django-dynamic-formset contains the JS functionality to add/remove rows.
Thanks, I wasn't aware of that jquery library. It's better than what I'd hacked together myself to deal with this!
Hello, I have a question which I cannot find in the documentation. How to limit number of empty formsets it generates for CreateWithInlinesView and UpdateWithInlinesView. It always genereates 3 empty formsets.
I would like to have one formset per existing related entry and one extra for adding new entries.
best regards Bastian