Improve on #69, using setdefault() and update example project
Camp site rule; leave things tidier than you found them :)
This commit is contained in:
@@ -6,6 +6,14 @@ from pexp.models import *
|
||||
class ProjectChildAdmin(PolymorphicChildModelAdmin):
|
||||
base_model = Project
|
||||
|
||||
# On purpose, only have the shared fields here.
|
||||
# The fields of the derived model should still be displayed.
|
||||
base_fieldsets = (
|
||||
("Base fields", {
|
||||
'fields': ('topic',)
|
||||
}),
|
||||
)
|
||||
|
||||
class ProjectAdmin(PolymorphicParentModelAdmin):
|
||||
base_model = Project
|
||||
list_filter = (PolymorphicChildModelFilter,)
|
||||
|
||||
@@ -411,8 +411,8 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin):
|
||||
kwargs.setdefault('form', self.base_form or self.form)
|
||||
|
||||
# prevent infinite recursion in django 1.6+
|
||||
if 'fields' not in kwargs and not self.declared_fieldsets:
|
||||
kwargs['fields'] = None
|
||||
if not self.declared_fieldsets:
|
||||
kwargs.setdefault('fields', None)
|
||||
|
||||
return super(PolymorphicChildModelAdmin, self).get_form(request, obj, **kwargs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user