summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-06-29 10:52:30 -0500
committerDan McGee <dan@archlinux.org>2011-07-05 09:44:45 -0500
commit5e85c5ac9ed09551d65ec07767094770d248f3b1 (patch)
tree8efdc0c1231617427727fc1291b8c8cda7dafd97 /main
parent33b9bf44aac4b70fa4cc6e9d1e82fb556b836801 (diff)
Move set_created_field() to shared utils class
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'main')
-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: