[ACCEPTED]-Is it OK to use multiple inheritance with Django abstract models?-django-models
If you use any fields at all in your class, inherit from 8 models.Model
.
Otherwise Django will ignore those fields 7 (the attributes will still be there in Python, but 6 no fields will be created in the DB). Set 5 abstract = True
to get "mixin" like behavior (i.e. no DB 4 tables will be created for the mixins but 3 for the models using those mixins).
If you 2 don't use any fields, you can just inherit 1 from object
, to keep things plain and simple.
I do this all the time with my classes and 2 model classes. It's one of the best things 1 in Python, in my opinion.
Sounds like for what you're trying to do, mixins really 7 are the best fit. A simple google search 6 will find lots of articles on implementing 5 mixins in python, such as this one. I'm not sure 4 multiple inheritance is the best way to 3 go about doing it, so you might want to 2 explore all the other options. What else 1 have you thought about?
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.