Fix admin validation errors related to additional non-model form fields.

fix_request_path_info
Diederik van der Boor 2013-09-05 11:36:54 +02:00
parent e1cecc1a91
commit 638ecd5813
2 changed files with 7 additions and 1 deletions

View File

@ -8,6 +8,7 @@ Version 0.5.2 (unreleased)
* Fix unwanted ``___`` handling in the ORM when a field name starts with an underscore; * Fix unwanted ``___`` handling in the ORM when a field name starts with an underscore;
this detects you meant ``relatedfield__ _underscorefield`` instead of ``ClassName___field``. 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 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) Version 0.5.1 (2013-07-05)

View File

@ -479,6 +479,11 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin):
return self.base_fieldsets 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): def get_subclass_fields(self, request, obj=None):
# Find out how many fields would really be on the form, # Find out how many fields would really be on the form,
# if it weren't restricted by declared fields. # 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, # By not declaring the fields/form in the base class,
# get_form() will populate the form with all available fields. # 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)) 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. # Find which fields are not part of the common fields.