Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix prefix increment for polymorphic forms - INT-3275 #267

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions nested_admin/nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,6 @@ def _create_formsets(self, request, obj, change):
is_empty_form = True
InlineFormSet = inline.get_formset(request, form_obj)

prefix = '%s-%s' % (form_prefix, InlineFormSet.get_default_prefix())
prefixes[prefix] = prefixes.get(prefix, 0) + 1
if prefixes[prefix] != 1:
prefix = "%s-%s" % (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 @@ -378,6 +373,11 @@ def _create_formsets(self, request, obj, change):
if not isinstance(form_obj, inline.parent_model):
continue

prefix = '%s-%s' % (form_prefix, InlineFormSet.get_default_prefix())
prefixes[prefix] = prefixes.get(prefix, 0) + 1
if prefixes[prefix] != 1:
prefix = "%s-%s" % (prefix, prefixes[prefix])

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