Skip to content

Instantly share code, notes, and snippets.

@mhulse
Created May 23, 2011 16:43
Show Gist options
  • Save mhulse/987022 to your computer and use it in GitHub Desktop.
Save mhulse/987022 to your computer and use it in GitHub Desktop.
Abstract class for generic fields; in this case "created" and "modified".
# ...
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