@@ -14,7 +14,6 @@ class UnsupportedChildType(LookupError):
1414 pass
1515
1616
17-
1817class PolymorphicFormSetChild (object ):
1918 """
2019 Metadata to define the inline of a polymorphic child.
@@ -46,7 +45,7 @@ def content_type(self):
4645 Expose the ContentType that the child relates to.
4746 This can be used for the ''polymorphic_ctype'' field.
4847 """
49- return ContentType .objects .get_for_model (self .model )
48+ return ContentType .objects .get_for_model (self .model , for_concrete_model = False )
5049
5150 def get_form (self , ** kwargs ):
5251 """
@@ -161,7 +160,7 @@ def _construct_form(self, i, **kwargs):
161160 if self .is_bound :
162161 if 'instance' in defaults :
163162 # Object is already bound to a model, won't change the content type
164- model = defaults ['instance' ].get_real_concrete_instance_class () # respect proxy models
163+ model = defaults ['instance' ].get_real_instance_class () # allow proxy models
165164 else :
166165 # Extra or empty form, use the provided type.
167166 # Note this completely tru
@@ -177,7 +176,7 @@ def _construct_form(self, i, **kwargs):
177176 raise UnsupportedChildType ("Child model type {0} is not part of the formset" .format (model ))
178177 else :
179178 if 'instance' in defaults :
180- model = defaults ['instance' ].get_real_concrete_instance_class () # respect proxy models
179+ model = defaults ['instance' ].get_real_instance_class () # allow proxy models
181180 elif 'polymorphic_ctype' in defaults .get ('initial' , {}):
182181 model = defaults ['initial' ]['polymorphic_ctype' ].model_class ()
183182 elif i < len (self .queryset_data ):
@@ -196,7 +195,7 @@ def _construct_form(self, i, **kwargs):
196195
197196 def add_fields (self , form , index ):
198197 """Add a hidden field for the content type."""
199- ct = ContentType .objects .get_for_model (form ._meta .model )
198+ ct = ContentType .objects .get_for_model (form ._meta .model , for_concrete_model = False )
200199 choices = [(ct .pk , ct )] # Single choice, existing forms can't change the value.
201200 form .fields ['polymorphic_ctype' ] = forms .ChoiceField (choices = choices , initial = ct .pk , required = False , widget = forms .HiddenInput )
202201 super (BasePolymorphicModelFormSet , self ).add_fields (form , index )
0 commit comments