On Thu, Jul 9, 2009 at 12:01 PM, Michael Stevens <mpsteven...@gmail.com>wrote:
> > Hi. > > I'm trying to use a model formset. > > I've successfully got it rendering data from the database and showing > it on a form to edit, but I'm now trying to recreate the data in save. > > So I've got: > FooFormset = modelformset_factory(Foo exclude = ['id', 'foo']) > foo_formset = FooFormset(request.POST, request.FILES, > queryset=Foo.objects.filter(...)) > > Without the "request.POST", it works, with the request.POST I get: > > Environment: > > Request Method: POST > Request URL: ... > Django Version: 1.0.2 final > Python Version: 2.3.4 > Installed Applications: > [...) > Installed Middleware: > ('django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware') > > > Traceback: > File "/opt/dev/python/modules/django/core/handlers/base.py" in get_response > 86. response = callback(request, *callback_args, > **callback_kwargs) > File "/opt/dev/python/django/.../manager/views.py" in smartad_edit > 39. foo_formset = FooFormSet(request.POST, request.FILES, > queryset=Foo.objects.filter(...)) > File "/opt/dev/python/modules/django/forms/models.py" in __init__ > 352. super(BaseModelFormSet, self).__init__(**defaults) > File "/opt/dev/python/modules/django/forms/formsets.py" in __init__ > 67. self._construct_forms() > File "/opt/dev/python/modules/django/forms/formsets.py" in _construct_forms > 76. self.forms.append(self._construct_form(i)) > File "/opt/dev/python/modules/django/forms/models.py" in _construct_form > 356. kwargs['instance'] = self.get_queryset()[i] > File "/opt/dev/python/modules/django/db/models/query.py" in __getitem__ > 221. return self._result_cache[k] > > Exception Type: IndexError at /... > Exception Value: list index out of range > > I've censored the stack trace a little to remove anything too sensitive. > > What am I doing wrong? > Are you passing the same queryset in when you create the form for POST as you did for GET? Without actually looking at the code I think what is happening here is you have data for more items in the POST dictionary than you have in your passed queryset. Karen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---