- Django 2 Web Development Cookbook
- Jake Kronika Aidas Bendoraitis
- 66字
- 2021-06-10 19:31:33
How to do it...
Open the models.py file of your utils package, and insert the following content there:
# utils/models.py
from django.db import models
from django.utils.translation import ugettext_lazy as _
class CreationModificationDateMixin(models.Model):
"""
Abstract base class with a creation
and modification date and time
"""
class Meta:
abstract = True
created = models.DateTimeField(
_("creation date and time"),
auto_now_add=True)
updated = models.DateTimeField(
_("modification date and time"),
auto_now=True)