On Wed, 2009-03-04 at 11:44 -0800, Margie wrote:
> Hi Malcolm.  So after reviewing your pointers, I had high hopes of
> being able to move to using the modelformset_factory, but I still seem
> to have problems.  The problem I run into is that when _construct_form
> (the one in django/forms/models.py) is called, it tries to do this:
> 
>         if i < self._initial_form_count:
>             kwargs['instance'] = self.get_queryset()[i]
> 
> I have no objects of my model yet and get_queryset()  returns
> self._queryset, which is [].  The above [i] index then causes a 'list
> index out of range exception'.  I think this was what I first
> encountered which made me think that I had to have a queryset to use
> modelformset_factory.

That second line of code will only be executed if
self._initial_form_count is greater than 0. You aren't providing any
initial forms, so it should be zero.

Looking at the source (it's set in the BaseFormset.__init__ method), it
will only be non-zero if you supply initial data, which kind of makes
sense, since providing initial data for "extra" forms would mean you'd
always end up creating a new record every time you viewed and submitted
that form. I can see why it's set up that way, although it confirms my
wish to spend a couple of days going over the formsets documentation
with a two-by-four.

I think it means that supplying this tile id via initial data is
probably not a great idea, as it will inadvertently create new records
own the track. I'd kind of been thinking that approach might have been a
little clunky, anyway, so this backs up that hunch. I'll put some more
details in the formset initialization thread, because it's probably more
appropriate there.

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