Skip to content

Commit

Permalink
Fix support for proxy models in formsets and admin inlines
Browse files Browse the repository at this point in the history
  • Loading branch information
vdboor committed Oct 8, 2017
1 parent cafaf95 commit ca6a604
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion polymorphic/admin/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def content_type(self):
Expose the ContentType that the child relates to.
This can be used for the ``polymorphic_ctype`` field.
"""
return ContentType.objects.get_for_model(self.model)
return ContentType.objects.get_for_model(self.model, for_concrete_model=False)

def get_formset_child(self, request, obj=None, **kwargs):
# Similar to GenericInlineModelAdmin.get_formset(),
Expand Down
2 changes: 1 addition & 1 deletion polymorphic/admin/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __iter__(self):
"""
for form, original in zip(self.formset.initial_forms, self.formset.get_queryset()):
# Output the form
model = original.get_real_concrete_instance_class()
model = original.get_real_instance_class()
child_inline = self.opts.get_child_inline_instance(model)
view_on_site_url = self.opts.get_view_on_site_url(original)

Expand Down
7 changes: 3 additions & 4 deletions polymorphic/formsets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class UnsupportedChildType(LookupError):
pass



class PolymorphicFormSetChild(object):
"""
Metadata to define the inline of a polymorphic child.
Expand Down Expand Up @@ -46,7 +45,7 @@ def content_type(self):
Expose the ContentType that the child relates to.
This can be used for the ''polymorphic_ctype'' field.
"""
return ContentType.objects.get_for_model(self.model)
return ContentType.objects.get_for_model(self.model, for_concrete_model=False)

def get_form(self, **kwargs):
"""
Expand Down Expand Up @@ -161,7 +160,7 @@ def _construct_form(self, i, **kwargs):
if self.is_bound:
if 'instance' in defaults:
# Object is already bound to a model, won't change the content type
model = defaults['instance'].get_real_concrete_instance_class() # respect proxy models
model = defaults['instance'].get_real_instance_class() # allow proxy models
else:
# Extra or empty form, use the provided type.
# Note this completely tru
Expand All @@ -177,7 +176,7 @@ def _construct_form(self, i, **kwargs):
raise UnsupportedChildType("Child model type {0} is not part of the formset".format(model))
else:
if 'instance' in defaults:
model = defaults['instance'].get_real_concrete_instance_class() # respect proxy models
model = defaults['instance'].get_real_instance_class() # allow proxy models
elif 'polymorphic_ctype' in defaults.get('initial', {}):
model = defaults['initial']['polymorphic_ctype'].model_class()
elif i < len(self.queryset_data):
Expand Down

0 comments on commit ca6a604

Please sign in to comment.