Two scoops of Django, best practices for Django 1.8 by Daniel Roy Greenfeld and Audrey Roy Greenfeld.
Paragraph 10.2 Using Mixins with CBWs:
Mixins should inherit from Python’s built-in object type.
And example:
from django.views.generic import TemplateView
class FreshFruitMixin(object):
def get_context_data(self, **kwargs):
context = super(FreshFruitMixin, self).get_context_data(**kwargs)
context["has_fresh_fruit"] = True
return context
class FruityFlavorView(FreshFruitMixin, TemplateView):
template_name = "fruity_flavor.html"
I just can't catch the idea. Why should we inherit from object? Can't we write something like this?
class ClassNameMixin:
<statement-1>
This will be the same. So, I just can't understand why inheriting from object is that important here.
Then, the mixin performs something. Can't it inherit from some fruitful class?