-
Book Overview & Buying
-
Table Of Contents
Web Development with Django Cookbook - Second Edition
By :
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, where you want to use the mixins and type the following code:
# demo_app/models.py
# -*- coding: UTF-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils...
Change the font size
Change margin width
Change background colour