File size: 718 Bytes
16bfc87 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
nb = dict(null=True, blank=True)
class CreateTracker(models.Model):
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
class Meta:
abstract = True
ordering = ('-created_at',)
class CreateUpdateTracker(CreateTracker):
updated_at = models.DateTimeField(auto_now=True)
class Meta(CreateTracker.Meta):
abstract = True
class GetOrNoneManager(models.Manager):
"""returns none if object doesn't exist else model instance"""
def get_or_none(self, **kwargs):
try:
return self.get(**kwargs)
except ObjectDoesNotExist:
return None
|