Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc82a84

Browse files
fdintinofelton
andauthored
Fix prefix increment for polymorphic forms (#274)
Co-authored-by: Felton <[email protected]>
1 parent c4aa19b commit fc82a84

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

nested_admin/nested.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,20 +368,22 @@ def _create_formsets(self, request, obj, change):
368368
is_empty_form = True
369369
InlineFormSet = inline.get_formset(request, form_obj)
370370

371+
# Check if we're dealing with a polymorphic instance, and if
372+
# so, skip inlines for other child models
373+
if hasattr(form_obj, "get_real_instance"):
374+
if hasattr(InlineFormSet, "fk"):
375+
rel_model = InlineFormSet.fk.remote_field.model
376+
if not isinstance(form_obj, rel_model):
377+
continue
378+
371379
prefix = "{}-{}".format(
372380
form_prefix, InlineFormSet.get_default_prefix()
373381
)
374382
prefixes[prefix] = prefixes.get(prefix, 0) + 1
375383
if prefixes[prefix] != 1:
376384
prefix = "{}-{}".format(prefix, prefixes[prefix])
377385

378-
# Check if we're dealing with a polymorphic instance, and if
379-
# so, skip inlines for other child models
380386
if hasattr(form_obj, "get_real_instance"):
381-
if hasattr(InlineFormSet, "fk"):
382-
rel_model = InlineFormSet.fk.remote_field.model
383-
if not isinstance(form_obj, rel_model):
384-
continue
385387
if not isinstance(form_obj, inline.parent_model):
386388
continue
387389

0 commit comments

Comments
 (0)