diff options
author | Dan McGee <dan@archlinux.org> | 2011-06-29 17:52:30 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-07-05 16:44:45 +0200 |
commit | 5e85c5ac9ed09551d65ec07767094770d248f3b1 (patch) | |
tree | 8efdc0c1231617427727fc1291b8c8cda7dafd97 /main | |
parent | 33b9bf44aac4b70fa4cc6e9d1e82fb556b836801 (diff) | |
download | archweb-5e85c5ac9ed09551d65ec07767094770d248f3b1.tar.gz archweb-5e85c5ac9ed09551d65ec07767094770d248f3b1.tar.xz |
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.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/main/utils.py b/main/utils.py index 12d1250..2ca69bc 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: |