summaryrefslogtreecommitdiff
path: root/main/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'main/utils.py')
-rw-r--r--main/utils.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/main/utils.py b/main/utils.py
index 12d12503..2ca69bcb 100644
--- a/main/utils.py
+++ b/main/utils.py
@@ -2,6 +2,9 @@ try:
import cPickle as pickle
except ImportError:
import pickle
+
+from datetime import datetime
+
from django.core.cache import cache
from django.utils.hashcompat import md5_constructor
@@ -81,4 +84,11 @@ def retrieve_latest(sender):
pass
return None
+def set_created_field(sender, **kwargs):
+ '''This will set the 'created' field on any object to datetime.utcnow() if
+ it is unset. For use as a pre_save signal handler.'''
+ obj = kwargs['instance']
+ if hasattr(obj, 'created') and not obj.created:
+ obj.created = datetime.utcnow()
+
# vim: set ts=4 sw=4 et: