Skip to content

Commit

Permalink
Merge pull request #321 from skirsdeda/admin_fieldsets_fix
Browse files Browse the repository at this point in the history
Do not use deprecated and removed declared_fieldsets attribute in admin
  • Loading branch information
vdboor committed Nov 20, 2017
2 parents 04b5fb4 + 5e150ea commit 0367d5f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Changes in git
* Added ``PolymorphicTypeInvalid`` exception when database was incorrectly imported.
* Added ``polymorphic.utils.get_base_polymorphic_model()`` to find the base model for types.
* Using ``base_model`` on the polymorphic admins is no longer required, as this can be autodetected.
* Fixed detection and handling of ``declared_fieldsets`` in the admin.
* Fixed manager errors for swappable models.
* Fixed deleteText of ``|as_script_options`` template filter.
* Improved ``polymorphic.utils.reset_polymorphic_ctype()`` to accept models in random ordering.
* Fix fieldsets handling in the admin (``declared_fieldsets`` is removed since Django 1.9)


Version 1.3 (2017-08-01)
Expand Down
9 changes: 2 additions & 7 deletions polymorphic/admin/childadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ def get_form(self, request, obj=None, **kwargs):
# If the derived class sets the model explicitly, respect that setting.
kwargs.setdefault('form', self.base_form or self.form)

# prevent infinite recursion in django 1.6+
if not getattr(self, 'declared_fieldsets', None):
kwargs.setdefault('fields', None)

return super(PolymorphicChildModelAdmin, self).get_form(request, obj, **kwargs)

def get_model_perms(self, request):
Expand Down Expand Up @@ -186,9 +182,8 @@ def history_view(self, request, object_id, extra_context=None):
# ---- Extra: improving the form/fieldset default display ----

def get_fieldsets(self, request, obj=None):
# If subclass declares fieldsets, this is respected
if (hasattr(self, 'declared_fieldsets') and self.declared_fieldsets) \
or not self.base_fieldsets:
# If subclass declares fieldsets or fields, this is respected
if hasattr(self, 'fieldsets') or hasattr(self, 'fields') or not self.base_fieldsets:
return super(PolymorphicChildModelAdmin, self).get_fieldsets(request, obj)

# Have a reasonable default fieldsets,
Expand Down

0 comments on commit 0367d5f

Please sign in to comment.