Reputation: 33
I'd been searching two days how to make it, and the other question I found are not my problem. I have 3 models:
class ProductBase(models.Model):
title = models.CharField(max_length=50) # and some code
class Serie(models.Model):
#some specific fields
productbase = models.OneToOneField(ProductBase, on_delete=models.CASCADE)
class Movie(models.Model):
#some specific fields
productbase = models.OneToOneField(ProductBase, on_delete=models.CASCADE)
The Admin shows me a Create/Edit Form for the ProductBase Model, one for the Serie Model, and one for the Movie Model. But I want to show a Create/Edit Form for Serie/ProductBase Model, and one for Movie/ProductBase Model, so creating a serie, I create a ProductBase and a Serie Model, and a relations between them. I thoght using Inlines but, that's for de ProductBase and I can't regsiter the ProductBAse two times with different AdminModels and Inlines. The other way is breaking the ProductBase in the two models Serie and Movie, but that is a bad design. Thanks for your help Sorry for my English
Upvotes: 1
Views: 363
Reputation: 236
I think abstract models is what you are looking for.
For example:
class AbstractProductBase(models.Model):
title = models.CharField(max_length=50)
class Meta:
abstract = True
class Serie(AbstractProductBase):
# some specific fields
class Movie(AbstractProductBase):
# some specific fields
Source: https://docs.djangoproject.com/en/1.9/topics/db/models/#abstract-base-classes
Upvotes: 2