Make your Django models inherit from the below abstract class. You models will get automatically timestamped upon creation and update of instances.
from django.db import models
class TimeStampedModel(models.Model):
"""
An abstract base class model that provides self-updating
``created_at`` and ``updated_at`` fields.
"""
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
Join my free newsletter BORING BACKEND. Soon i'll be starting mentoring people by doing micro-projects.
Top comments (0)