Skip to content

Commit ca6a604

Browse files
committed
Fix support for proxy models in formsets and admin inlines
1 parent cafaf95 commit ca6a604

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

polymorphic/admin/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def content_type(self):
4242
Expose the ContentType that the child relates to.
4343
This can be used for the ``polymorphic_ctype`` field.
4444
"""
45-
return ContentType.objects.get_for_model(self.model)
45+
return ContentType.objects.get_for_model(self.model, for_concrete_model=False)
4646

4747
def get_formset_child(self, request, obj=None, **kwargs):
4848
# Similar to GenericInlineModelAdmin.get_formset(),

polymorphic/admin/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __iter__(self):
4242
"""
4343
for form, original in zip(self.formset.initial_forms, self.formset.get_queryset()):
4444
# Output the form
45-
model = original.get_real_concrete_instance_class()
45+
model = original.get_real_instance_class()
4646
child_inline = self.opts.get_child_inline_instance(model)
4747
view_on_site_url = self.opts.get_view_on_site_url(original)
4848

polymorphic/formsets/models.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class UnsupportedChildType(LookupError):
1414
pass
1515

1616

17-
1817
class 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):

0 commit comments

Comments
 (0)