It is a common behavior to have timestamps in your models for the creation and modification of your model instances. In this recipe, we will see how to create a simple model mixin that saves the creation and modification dates and times for your model. Using such a mixin will ensure that all the models use the same field names for the timestamps and have the same behavior.
If you haven't done this yet, create the utils
package to save your mixins. Then, create the models.py
file in the utils
package.
Open the models.py
file of your utils
package and insert the following content there:
# utils/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.timezone import now as timezone_now class CreationModificationDateMixin(models.Model): """ Abstract base class with a creation and modification...