On Wed, 2009-03-04 at 19:47 -0800, Margie wrote:
> Yes, I agree with what you are saying about self._initial_form_count
> being set to a number greater than zero due to me using initial in my
> code that creates the formset, as follows:
> 
> def makeTaskDetailFormSetForCreate(tileList, data=None):
>     TaskDetailFormSet = modelformset_factory(TaskDetail,
>                                              form=TaskDetailForm,
>  
> formset=TaskDetailCustomBaseFormSetForCreate)
> 
>     taskDetailFormSet = TaskDetailFormSet(data=data,
>                                           tiles=tileList,
>                                           initial=[{"tile":tile.id}
> for tile in tileList])
> 
>     return taskDetailFormSet
> 
> But if I don't use initial - how do I create the initial values for
> the forms?  I thought using initial is the "right" way to do it?

I mentioned before that initial data doesn't necessarily make sense for
new models in a modelformset, in some ways (in other ways it does -- but
it's not really practical to handle every single possibility, so
sometimes you just have to deal with it). The thing is that initial data
always results in a populated form -- so data is submitted and a new
entry will be created. That doesn't work for "extra" forms, in the
formset sense, where you're only going to enter new data and, if you
don't, they won't have any effect on things.

If you really, really want to prepopulate fields and can also have some
way to work out whether the data is "new" or the "initial" stuff, then
you'll be able to use it, but you'll have to do some of the form
handling yourself. Reading the source and thinking very hard about
things is the solution to that problem. I'm sure it's possible, but it
will take some thinking. At some point, you just have to say it's not a
standard modelformset case and let go of that particular aid.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to