From 132a10c98e400fa2362fc7d8cd2191d591577504 Mon Sep 17 00:00:00 2001 From: Felton <23240+felton@users.noreply.github.com> Date: Fri, 10 Jan 2025 17:47:04 -0500 Subject: [PATCH] Fix prefix increment for polymorphic forms --- nested_admin/nested.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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