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.

I cleaned up other things that you mentioned in your other posts  -
thanks much for those pointers.  I've put my current code at

http://dpaste.com/6281/

Note that when I instantiate the formset:

taskTileDetailFormSet = TaskTileDetailFormSet(data=data,
                                                  tiles=tileList,
                                                  initial=
[{"tile":tile.id} for tile in tileList]

I am creating an initial entry for each form that I want created.
Inside __init__ for TaskDetailCustomBaseFormSetForCreate I thus set
self.extra to 0.  My understanding is that I don't need any "extras"
in this case because I am using initial to specify all of the forms
that I want.  (Setting extra to a larger number had no effect on the
list index error - am just mentioning this for clarity)

Anyway, I must be doing something dumb... sigh.  The
modelformset_factory works fine for me in another case query I have an
existing set of model instances - just can't get it to work in this
case where I don't yet have the model instances.

Thanks for any pointers.

Margie






On Mar 3, 10:54 pm, Margie <margierogin...@yahoo.com> wrote:
> Yeah, I need to go back and review.  I think my original problem was
> that I just didn't think about using extra to define the intial forms
> - I was thinking I needed a queryset.   Your first resonse addressed
> that. But then you mentioned something about exclude and that made me
> think that maybe I couldn't use it.  Of course I can.
>
> Anyway, I need to see if I can get myself back to a steady working
> state and then am going to revisit using the modelformset_factory.
> Thanks for the pointers.
>
> Margie
>
> On Mar 3, 10:24 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
> wrote:
>
> > On Wed, 2009-03-04 at 16:49 +1100, Malcolm Tredinnick wrote:
> > > On Tue, 2009-03-03 at 21:44 -0800,Margiewrote:
>
> > > > My model does have multiple fields in it - the Book thing was just an
> > > > example to simplify.  And I do have fields that I need to exclude.  Am
> > > > I not able to exclude fields with the modelformset_factory?  
>
> > > The example code I have showed fields being excluded.
>
> > Gargh. Important typo: that should have said "the example code I have
> > *posted*", in my previous post.
>
> > Also, the documentation for model forms shows, similarly, how to exclude
> > fields ([1]). So I don't understand your question.
>
> > [1]http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#control...
>
> > 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 django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to