- Django 3 Web Development Cookbook
- Aidas Bendoraitis Jake Kronika
- 68字
- 2025-04-04 13:15:07
How to do it...
Open the models.py file in your myprojects.apps.core package, and insert the following content there:
# myproject/apps/core/models.py
from django.db import models
from django.utils.translation import gettext_lazy as _
class CreationModificationDateBase(models.Model):
"""
Abstract base class with a creation and modification date and time
"""
created = models.DateTimeField(
_("Creation Date and Time"),
auto_now_add=True,
)
modified = models.DateTimeField(
_("Modification Date and Time"),
auto_now=True,
)
class Meta:
abstract = True