Last active
August 3, 2017 17:10
-
-
Save gepatino/706d4fdd0cb1fbd026a656268a620f56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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