Brush up the `ParentAdminNotRegistered` fix a bit for flow clarity.
parent
3570d10754
commit
58f89efa5d
|
|
@ -10,6 +10,7 @@ Changes in git
|
|||
* Fixed ``polymorphic_modelformset_factory()`` usage.
|
||||
* Fixed Python 3 bug for inline formsets.
|
||||
* 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)
|
||||
|
|
|
|||
|
|
@ -126,20 +126,17 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin):
|
|||
try:
|
||||
return self.admin_site._registry[parent_model]
|
||||
except KeyError:
|
||||
# Admin is not registered for polymorphic_ctype model, but it may
|
||||
# be registered for a model in the class ancestry between this
|
||||
# model and the root parent one.
|
||||
# Admin is not registered for polymorphic_ctype model, but perhaps it's registered
|
||||
# for a intermediate proxy model, between the parent_model and this 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):
|
||||
continue
|
||||
# Fetch admin instance for model class (may return None)
|
||||
continue # e.g. found a mixin.
|
||||
|
||||
# Fetch admin instance for model class, see if it's a possible candidate.
|
||||
model_admin = self.admin_site._registry.get(klass)
|
||||
# Ignore admin (or None) that isn't a polymorphic parent admin
|
||||
if not isinstance(model_admin, PolymorphicParentModelAdmin):
|
||||
continue
|
||||
if model_admin is not None and isinstance(model_admin, PolymorphicParentModelAdmin):
|
||||
return model_admin # Success!
|
||||
|
||||
# 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))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue