catherine
catherine

Reputation: 22808

Model Inheritance

Which is better to use among all of the model inheritance and why? I do not have knowledge about it so I want to know which better, or more useful so that I will know which is I will use for that particular scenario.

Upvotes: 0

Views: 191

Answers (1)

Aidan Ewen
Aidan Ewen

Reputation: 13328

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.

Upvotes: 1

Related Questions