Skip to content

Instantly share code, notes, and snippets.

@DataGreed
Created April 5, 2022 15:56
Show Gist options
  • Save DataGreed/d45c97ef1f322b35c110320941fbe26f to your computer and use it in GitHub Desktop.
Save DataGreed/d45c97ef1f322b35c110320941fbe26f to your computer and use it in GitHub Desktop.
base model for Django projects with autopopulated date_created and date_modified fields
class BaseModel(models.Model):
"""
Base abstract model that adds created and modified dates.
Inherit from it when defining models.
"""
class Meta:
abstract = True
date_created = models.DateTimeField("Date Created", auto_now_add=True)
date_modified = models.DateTimeField("Date Modified", auto_now=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment