How to pass the extra argument to an existing formset

23 views
Skip to first unread message

MH

unread,
Jun 12, 2020, 1:23:13 PM6/12/20
to Django users
Hi

I have a formset that is created by an inline formset factory. So, I have seen that during the creation I can pass the extra argument in order to create more blank forms. Fine :)

But I also have the case where I want to pre-populate a formset based on entries in the database. In a way I thought I could just hit the database and lookup the number of matching entries like objects = Model.objects.filter(id=thatid).values().
And then I could pass the individual entry data to the forms in the formset. I have managed to do this for one form in the formset, but I do not know how to get django to create a formset with x extra forms in it, based on the number of database entries. I guess I could again create one formset with an inline formset factory, but is it also possible to use the initial formset that I already created in my forms.py and to somehow pass the extra argument?

Best regards
Reply all
Reply to author
Forward
0 new messages