Created
May 23, 2011 16:43
-
-
Save mhulse/987022 to your computer and use it in GitHub Desktop.
Abstract class for generic fields; in this case "created" and "modified".
This file contains 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
# ... | |
class Base(models.Model): | |
created = models.DateTimeField(_(u'Created'), editable=False) | |
modified = models.DateTimeField(_(u'Modified'), editable=False) | |
class Meta: | |
abstract = True | |
def save(self, *args, **kwargs): | |
if not self.pk: | |
self.created = datetime.datetime.now() | |
self.modified = datetime.datetime.now() | |
super(Base, self).save(*args, **kwargs) | |
@property | |
def is_modified(self): | |
return self.modified > self.created | |
# ... | |
class Project(Base): | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment