The problem
Suppose I have three classes A, B and C, where B is a subclass of A and C is a subclass of B:
A <- B <- C
When I open up the admin and list all "A"s, I see all "A"s, "B"s and "C"s. But when I follow one of those links, to see the details and edit that particular B, I will see only the fields of B, even if that instance is actually an instance of C. What I would like to see is the object to be shown to me according to its most specific type.
What I'm trying
I'm using InheritanceManager to get instances casted to the right type when working at a more abstract level. This works almost well (it can't handle more than one inheritance level). However, even for a single inheritance level, I can't get the polymorphic behavior to be reflected in the admin, as obviously the admin doesn't know about the manager's select_subclasses()
method.
Any idea on how could I use to get such a polymorphic-like behavior on the admin?
Concrete Example
models.py:
from django.db import models
from model_utils.managers import InheritanceManager
class A(models.Model):
a_field = models.CharField(max_length=200)
objects = InheritanceManager()
class B(A):
b_field = models.CharField(max_length=200)
class C(B):
c_field = models.CharField(max_length=200)
admin.py
from myapp.models import A, B, C
from django.contrib import admin
admin.site.register(A)
admin.site.register(B)
admin.site.register(C)
Update
Adding a link to two threads from 2010 with some thoughts on how to achieve this with django-polymorphic: