@@ -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