From bf4385a26c1b6f07bf9bdcddf7160b5eb4a71d9a Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 27 Dec 2012 21:13:56 -0600 Subject: Move the body of set_last_modified to main/utils Instead of having multiple methods, move this into our single 'created' setter method. If the 'last_modified' property is present, we now update it accordingly when saving any model with this signal attached. Signed-off-by: Dan McGee --- main/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'main') diff --git a/main/utils.py b/main/utils.py index d12e5e1..17ca386 100644 --- a/main/utils.py +++ b/main/utils.py @@ -106,10 +106,16 @@ def retrieve_latest(sender, latest_by=None): def set_created_field(sender, **kwargs): '''This will set the 'created' field on any object to the current UTC time - if it is unset. For use as a pre_save signal handler.''' + if it is unset. + Additionally, this will set the 'last_modified' field on any object to the + current UTC time on any save of the object. + For use as a pre_save signal handler.''' obj = kwargs['instance'] + time = now() if hasattr(obj, 'created') and not obj.created: - obj.created = now() + obj.created = time + if hasattr(obj, 'last_modified'): + obj.last_modified = time def database_vendor(model, mode='read'): -- cgit v1.2.3-24-g4f1b