Skip to content

Instantly share code, notes, and snippets.

@gepatino
Last active August 3, 2017 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gepatino/706d4fdd0cb1fbd026a656268a620f56 to your computer and use it in GitHub Desktop.
Save gepatino/706d4fdd0cb1fbd026a656268a620f56 to your computer and use it in GitHub Desktop.
from django.conf import settings
from django.db import model
class AuditedModel(models.Model):
created = models.DateTimeFIeld(auto_now_add=True)
created_by = models.ForeignKey(settings.AUTH_USER_MODEL)
updated = models.DateTimeField(auto_now=True)
updated_by = models.ForeignKey(settings.AUTH_USER_MODEL)
def save(self, *args, **kwargs):
# here set the users using the middleware function to get
# the current request or user, and call the parent's save()
class Meta:
abstract = True
# Then in your models:
class Person(AuditedModel):
name = models.CharField(max_length=40)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment