diff --git a/nested_admin/nested.py b/nested_admin/nested.py index a83b051..ccefd27 100644 --- a/nested_admin/nested.py +++ b/nested_admin/nested.py @@ -368,6 +368,14 @@ def _create_formsets(self, request, obj, change): is_empty_form = True InlineFormSet = inline.get_formset(request, form_obj) + # Check if we're dealing with a polymorphic instance, and if + # so, skip inlines for other child models + if hasattr(form_obj, "get_real_instance"): + if hasattr(InlineFormSet, "fk"): + rel_model = InlineFormSet.fk.remote_field.model + if not isinstance(form_obj, rel_model): + continue + prefix = "{}-{}".format( form_prefix, InlineFormSet.get_default_prefix() ) @@ -375,13 +383,7 @@ def _create_formsets(self, request, obj, change): if prefixes[prefix] != 1: prefix = "{}-{}".format(prefix, prefixes[prefix]) - # Check if we're dealing with a polymorphic instance, and if - # so, skip inlines for other child models if hasattr(form_obj, "get_real_instance"): - if hasattr(InlineFormSet, "fk"): - rel_model = InlineFormSet.fk.remote_field.model - if not isinstance(form_obj, rel_model): - continue if not isinstance(form_obj, inline.parent_model): continue