Brush up the `ParentAdminNotRegistered` fix a bit for flow clarity.

fix_request_path_info
Diederik van der Boor 2016-10-14 11:48:22 +02:00
parent 3570d10754
commit 58f89efa5d
2 changed files with 9 additions and 11 deletions

View File

@ -10,6 +10,7 @@ Changes in git
* Fixed ``polymorphic_modelformset_factory()`` usage. * Fixed ``polymorphic_modelformset_factory()`` usage.
* Fixed Python 3 bug for inline formsets. * Fixed Python 3 bug for inline formsets.
* Fixed CSS for Grappelli, so model choice menu properly overlaps. * Fixed CSS for Grappelli, so model choice menu properly overlaps.
* Fixed ``ParentAdminNotRegistered`` exception for models that are registered via a proxy model instead of the real base model.
Version 1.0.1 (2016-09-11) Version 1.0.1 (2016-09-11)

View File

@ -126,20 +126,17 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin):
try: try:
return self.admin_site._registry[parent_model] return self.admin_site._registry[parent_model]
except KeyError: except KeyError:
# Admin is not registered for polymorphic_ctype model, but it may # Admin is not registered for polymorphic_ctype model, but perhaps it's registered
# be registered for a model in the class ancestry between this # for a intermediate proxy model, between the parent_model and this model.
# model and the root parent one.
for klass in inspect.getmro(self.model): for klass in inspect.getmro(self.model):
# Ignore model ancestors that are not also subclasses of the
# target ctype model
if not issubclass(klass, parent_model): if not issubclass(klass, parent_model):
continue continue # e.g. found a mixin.
# Fetch admin instance for model class (may return None)
# Fetch admin instance for model class, see if it's a possible candidate.
model_admin = self.admin_site._registry.get(klass) model_admin = self.admin_site._registry.get(klass)
# Ignore admin (or None) that isn't a polymorphic parent admin if model_admin is not None and isinstance(model_admin, PolymorphicParentModelAdmin):
if not isinstance(model_admin, PolymorphicParentModelAdmin):
continue
return model_admin # Success! return model_admin # Success!
# If we get this far without returning there is no admin available # If we get this far without returning there is no admin available
raise ParentAdminNotRegistered("No parent admin was registered for a '{0}' model.".format(parent_model)) raise ParentAdminNotRegistered("No parent admin was registered for a '{0}' model.".format(parent_model))