One-to-one model fields in admin
This question has been floating around in one shape or another, but I couldn't find a definite answer to it.
Let's say I have this:
class BaseModel(models.Model):
base_field = models.CharField(max_length=10)
class ExtendedModelA(models.Model):
extended_field_a = models.CharField(max_length=10)
base = models.OneToOneField(BaseModel)
class ExtendedModelB(models.Model):
extended_开发者_StackOverflowfield_b = models.CharField(max_length=10)
base = models.OneToOneField(BaseModel)
Question is, how do I make BaseModel
field editable in admin interface when I click on either of ExtendedModel
instances.
I know I can reference ExtendedModel
as inline from Base
, but that does not make much sense to me as I want to create ExtendedModelA/B
who "inherit" stuff from Base
.
Googling around I found a solution on DjangoSnippets, but that doesn't work since 1.1+ and requires patch to Django which is ugly.
Is it very simple thing that everyone knows about but me, or noone does that at all??...
Try with multi table inheritance. It does what you want.
精彩评论