I have several models inheriting from a base model.
The fields in the base model are needed rarely, but Django keeps doing complex inner joins to retrieve those fields whenever I use any of the inherited models.
How can I tell Django to avoid this ? I only need the fields in this model rarely.
Note: maybe only(..) would work(I didn’t check), but I would need to add it in many places in the code..
Use abstract model inheritance.
In short, setting
abstract = Truein the base class’ meta, makes Django using abstract inheritance, meaning each derived model will contain a copy of all the fields defined in the base model.By the way, one of the Django’s maintainers, Jacob Kaplan-Moss has quite a strong opinion against concrete inheritance,
and again:
Personally, I have never had to use model inheritance at all; however, after reading that blog entry, I am quite convinced in trying to avoid concrete inheritance as much as possible.