At this point, we don't know why this line of code is executed, but
we do know it's not consistently executed between Django 1.10 and
Django 1.11 due to the addition of `ForwardOneToOneDescriptor`, a
subclass of `ForwardManyToOneDescriptor`.
Refs. 6628145af7
Refs. kavdev/dj-stripe#524
Refs. django/django@38575b007a
I'm a little concerned that this loses some of the efficiencies (in
particular, chunking) from previous versions. That's something that can
probably be improved.
This avoids the following error in django 1.11 tests:
polymorphic.MRODerived: (models.E005) The field 'id' from parent model 'polymorphic.mrobase3' clashes with the field 'id' from parent model 'polymorphic.mrobase1'.
Related to https://code.djangoproject.com/ticket/22442
This change fixes an issue where django-polymorphic raises a
`ParentAdminNotRegistered` exception when you register an admin for a
child model ancestor, but not for the root ancestor as pointed to by
the `polymorphic_ctype` field. This error occurs only when you *Save*
the child model detail form, not when you *Save and continue* on that
same form.
This situation occurs for us when using django-fluent-pages version
1.0.1 which has an intermediate `Page` model registered with a parent
admin to show the pages listing. The existing `_get_parent_admin` method
expects an admin to be registered for the root `UrlNode` model pointed
to by the `polymorphic_ctype` field.
This fix uses a potentially naive and slow brute-force approach where
it walks up the class hierarchy and checks whether a parent admin is
registered for each ancestor model, unless/until it finds one.
See also https://github.com/ic-labs/django-icekit/issues/31/
In Python 3.4 trying to generate a polymorphic_inlineformset results in a TypeError with the following message: "'KeysView' object does not support indexing". This solves that problem by ensuring that `child_models` is a list, and thus can be referenced by index.