August 2016
Beginner to intermediate
717 pages
15h 24m
English
In object-oriented languages, such as Python, a mixin class can be viewed as an interface with implemented features. When a model extends a mixin, it implements the interface and includes all its fields, properties, and methods. Mixins in Django models can be used when you want to reuse the generic functionalities in different models multiple times.
First, you will need to create reusable mixins. Some typical examples of mixins are given later in this chapter. A good place to keep your model mixins is in the utils module.
If you create a reusable app that you will share with others, keep the model mixins in the reusable app, for example, in the base.py file.
Open the models.py file of any Django app, ...
Read now
Unlock full access