Created
May 11, 2009 05:24
-
-
Save k0001/109876 to your computer and use it in GitHub Desktop.
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 UTCTimeAuditedModel(models.Model): | |
""" | |
Abastract model providing UTC time auditing. | |
Adds two fields `utc_created_at` set on first save of the instance, and | |
`utc_updated_at` updated on every item save to the current utc datetime | |
""" | |
utc_created_at = models.DateTimeField(editable=False, verbose_name=_(u"created at (utc)")) | |
utc_updated_at = models.DateTimeField(editable=False, verbose_name=_(u"updated at (utc)")) | |
class Meta: | |
abstract = True | |
def save(self, force_insert=False, force_update=False): | |
utcnow = datetime.datetime.utcnow() | |
if not self.pk: | |
self.utc_created_at = utcnow | |
self.utc_updated_at = utcnow | |
return super(UTCTimeAudited, self).save(force_insert, force_update) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment