Skip to content

Commit

Permalink
Fix prefix increment for polymorphic forms
Browse files Browse the repository at this point in the history
  • Loading branch information
felton committed Jan 8, 2025
1 parent f9508c4 commit 9e85722
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions nested_admin/nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,7 @@ def _create_formsets(self, request, obj, change):
form_obj = None
is_empty_form = True
InlineFormSet = inline.get_formset(request, form_obj)

prefix = "{}-{}".format(
form_prefix, InlineFormSet.get_default_prefix()
)
prefixes[prefix] = prefixes.get(prefix, 0) + 1
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"):
Expand All @@ -384,6 +377,13 @@ def _create_formsets(self, request, obj, change):
if not isinstance(form_obj, inline.parent_model):
continue

prefix = "{}-{}".format(
form_prefix, InlineFormSet.get_default_prefix()
)
prefixes[prefix] = prefixes.get(prefix, 0) + 1
if prefixes[prefix] != 1:
prefix = "{}-{}".format(prefix, prefixes[prefix])

formset_params = {
"instance": form_obj,
"prefix": prefix,
Expand Down

0 comments on commit 9e85722

Please sign in to comment.