This is a question about Python Mixins that may be useful in general. I just use Django models as this is the most suitable use case.
Should mixin inherit from the class it is intended to mix with or from an object?
Code examples, more correct or better, or better, depending on what you want to achieve?
it
class TaggingMixin(models.Model): tag = models.ForeignKey(Tag) class Meta: abstract = True class MyModel(models.Model, TaggingMixin): title = models.CharField(max_length=100)
Or that:
class TaggingMixin(object): tag = models.ForeignKey(Tag) class Meta: abstract = True class MyModel(models.Model, TaggingMixin): title = models.CharField(max_length=100)
I think object inheritance is correct. But I see examples of the first case throughout the network ...
EDIT: I moved my next question to a separate question: Django Abstract Models vs. plain Python mixins vs Python ABC
python
hopla Jul 15 '10 at 9:57 2010-07-15 09:57
source share