Sunday, July 31, 2011

Re: Nested formsets at Django 1.3

Kev Dwyer wrote:

> Hello List,
>
> I've been upgrading an old Django 1.1.x app to use Django 1.3, and am
> having a problem with nested formsets.
>
...
>
>
>
I omitted one important fact in this write-up. In Nathan's original code,
the lowest level formset is created like this:

TenantFormset(data=self.data,
instance=instance,
prefix='TENANTS_%s' % pk_value)

where instance is an instance of Building, the "parent" or container
for tenants and self is an instance of

class BaseBuildingFormset(BaseInlineFormSet)

which is instantiated like this:

BuildingFormset = inlineformset_factory(models.Block,
models.Building,
formset=BaseBuildingFormset,
extra=1)

I omitted to mention that to get around this I stopped passing in self.data,
which led to the behaviour that I described in my original post. Apologies
if this misled anyone.

Up to Django 1.2.5, Nathan's code works fine. However at 1.3, if self.data
is passed to TenantFormset, it turns out to be empty and a ValidationError
is raised because the ManagementForm information has not been supplied.
This is the intended consequewnce of #11418, AFAICT.

Working on the assumption that self.data should contain the
ManagementForm data I've tried populating it with said data, but
ValidationError is still raised.

My use case is slightly simpler than Nathan's example as I just need to edit
existing objects, so I'm going to try populating the formsets using
querysets rather than instances.

Does anyone have any other ideas on how this might be made to work?

Cheers,

Kev

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment