[Answer]-Model Inheritance

1👍

Each of these techniques provide different benefits. It really depends on what you need to do.

The best place to start is reading the model inheritance docs.

Abstract base classes

Use these if you’re just trying to reduce the amount of code you write. If you know that several fields appear in numerous models then write a base class and inherit it.

Multi-table inheritance

This is useful if you want a concrete base class that can be queried and operated on – for example Base.objects.all() is a bit like seeing Child1.objects.all() and Child2.objects.all() in the same queryset.

Proxy Models

Use proxy models if all the fields are the same across each model. You get one db tuple for each object, but that db tuple can be used to represent either the parent or the proxy. This is quite powerful, and almost certainly the way to go if your fields are the same.

Leave a comment