diff --git a/docs/changelog.rst b/docs/changelog.rst index 9c932e5..62c6227 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -8,6 +8,7 @@ Version 0.5.2 (unreleased) * Fix unwanted ``___`` handling in the ORM when a field name starts with an underscore; this detects you meant ``relatedfield__ _underscorefield`` instead of ``ClassName___field``. * Fix missing permission check in the "add type" view. This was caught however in the next step. +* Fix admin validation errors related to additional non-model form fields. Version 0.5.1 (2013-07-05) diff --git a/polymorphic/admin.py b/polymorphic/admin.py index 9bf80de..019415b 100644 --- a/polymorphic/admin.py +++ b/polymorphic/admin.py @@ -479,6 +479,11 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin): return self.base_fieldsets + def get_form(self, request, obj=None, **kwargs): + kwargs.setdefault('form', self.base_form) + return super(PolymorphicChildModelAdmin, self).get_form(request, obj, **kwargs) + + def get_subclass_fields(self, request, obj=None): # Find out how many fields would really be on the form, # if it weren't restricted by declared fields. @@ -487,7 +492,7 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin): # By not declaring the fields/form in the base class, # get_form() will populate the form with all available fields. - form = self.get_form(request, obj, exclude=exclude) + form = self.get_form(request, obj, exclude=exclude, form=self.base_form) subclass_fields = list(six.iterkeys(form.base_fields)) + list(self.get_readonly_fields(request, obj)) # Find which fields are not part of the common fields.