Wrong resolution of content type id for proxy models in ModelAdmin
|Reported by:||alejandro||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
I have a number of proxy models that I want to present separately in the admin interface. A simplified example would be:
class Accommodation(models.Model): name = models.CharField(max_length=10) class Inn(Accommodation): class Meta: proxy = True class Hotel(Accommodation): class Meta: proxy = True admin.site.register(Inn) admin.site.register(Hotel)
However, due to how ModelAdmin gets the content type of the models the retrieved content type instances will always be those corresponding to Accommodation. This causes several problems:
- The log entries shown in the admin index will have broken links because log entries have the content type id of Accommodation instead of Inn or Hotel.
- In the change form, the content_type_id context variable will be the one of Accommodation content type, causing the "View on site" link not to work.
I'm not sure wether there are more cases where getting the content type from the concrete model breaks things in the admin. A naive fix would be to pass for_concrete_model=False for every ContentType.objects.get_for_model call in ModelAdmin code but I'm not aware of the consequences of that since I'm not familiar enough with Django internals.
Change History (8)
comment:1 Changed 2 years ago by timo
- Has patch set
- Needs documentation unset
- Needs tests set
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
comment:5 Changed 22 months ago by Tim Graham <timograham@…>
- Resolution set to fixed
- Status changed from new to closed