Answer the question
In order to leave comments, you need to log in
How does Django deal with multiple model inheritance?
And what about mixins to models in Django (read multiple inheritance). Let's say I'm doing an online store, I have an Item model (product). Here I find out that for one type of goods there are characteristics (for example, length and color). And for another type there are other characteristics (material) and there are no first ones. There is no point in adding all properties to a common Item.
So, is it possible to create a CustomItem1 type mixin, create a NewItem (Item, CustomItem) model, and use the goodies of additional fields? Do the same for NewItem2. How will it look in the regular admin panel?
Can you give an example of working code?
Answer the question
In order to leave comments, you need to log in
django has abstract models where you can define the fields you want and apply that to the main model.
It is impossible to dynamically create such models. Each time you add a new model or fields to an existing model, you need to do a migration
Dividing a model into a bunch of submodels just because someone has one property and the other does not - that's where it makes no sense.
There are at least a couple of workflows for this:
1) JSON
2) EAV
The first option is preferred for postgresql. You can quite flexibly create indexes for specific fields inside json. The performance of json vs eav can be easily found on the internet.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question