On 20 nov, 06:54, "Brian Rosner" <[EMAIL PROTECTED]> wrote: > On Wed, Nov 19, 2008 at 10:23 PM, [EMAIL PROTECTED] > > > > <[EMAIL PROTECTED]> wrote: > > > On 20 nov, 06:01, "Brian Rosner" <[EMAIL PROTECTED]> wrote: > >> On Wed, Nov 19, 2008 at 9:53 PM, [EMAIL PROTECTED] > > >> <[EMAIL PROTECTED]> wrote: > > >> > I use a fake queryset because it's the only way that I found to > >> > populate the formset (using a real queryset would lead to the same > >> > problem anyway), hence I wonder if there is a cleaner way to do what I > >> > want without reinventing modelforms, or using separate form classes > >> > for saving and creating my dynamic formsets. > > >> I think from what I gather you are looking to create an "add"-only > >> model formset? If so take a look > >> athttp://code.djangoproject.com/ticket/9538. I have written some > >> information on that ticket that may be of use to you. > > > Yes I tried the approach you're talking about in the ticket: > > > FormSet = modelformset_factory(SomeModel, extra=3) > > > This creates 3 blank forms with INITIAL_FORMS=0, which is fine. But > > then how can I populate this formset with some initial data instead of > > the model's default values ? > > Can you file a ticket about this? The fundamental issue here is that > formsets use initial data to populate the forms, but model formsets > make no distinction between initial data being passed in and initial > data it makes via the queryset. It sounds worth fixing.
I think I misunderstood your first post, sorry. I tried to use formset_factory with my ModelForm based form : FormSet = formset_factory(SomeModelForm, extra=0) forms = FormSet(initial=[{"field": 1}, {"field": 2}, {"field": 3}]) It works (I thought you _had_ to use modelformset_factory to create ModelForm formsets). But then again, I get INITIAL_FORMS=3 in the output. If I set extra to 3, I still get INITIAL_FORMS=3, and 3 additional blank forms, there seems to be no way to populate the extra forms with initial data. So I think a new keyword argument is needed for formset_factory to solve this particular issue, perhaps extra_initial ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---