class Account(models.Model):
identifier = models.CharField(max_length=5)
objects = MyCustomManager()
class Meta:
abstract = True
class Customer(Account):
name = models.CharField(max_length=255)
If I have a lot of models, and I want to save time from having to put foreignkeys everywhere, is this right? Or, am I thinking of this all wrong?
It depends in which direction the foreign keys go. You cannot have a foreign key to an abstract class.
Maybe it is Generic Relations what is interesting for you or foreign keys in abstract model classes.
Although notice that inheritance is always a
is-arelationship while a normal foreign key usage implies ahas-arelationship.In your example,
Customershould not inherit fromAccountas a customer has an account.An inheritance example would be a Place which is either a Restaurant or a Cinema etc.
Edit after comment:
Well, there is a own section for this in the documentation:
I would only do if the inherited classes belong somehow to the same scope.
If you really a so many classes that it matters to add one line to these classes then you probably have not a good DB or application design.
And try not to put everything in one manager just to be able to use only one manager in a lot classes.