From e353a01a9a74bc624724e6e507b47e7697afe910 Mon Sep 17 00:00:00 2001 From: Keryn Knight Date: Tue, 1 Jul 2014 14:37:41 +0100 Subject: [PATCH] Implemented ability to change modified fields manually. --- model_utils/fields.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/model_utils/fields.py b/model_utils/fields.py index 8728d56..7fe1c83 100644 --- a/model_utils/fields.py +++ b/model_utils/fields.py @@ -30,8 +30,14 @@ class AutoLastModifiedField(AutoCreatedField): """ def pre_save(self, model_instance, add): - value = now() - setattr(model_instance, self.attname, value) + if add and hasattr(model_instance, self.attname): + # when creating an instance and the modified date is set + # don't change the value, assume the developer wants that + # control. + value = getattr(model_instance, self.attname) + else: + value = now() + setattr(model_instance, self.attname, value) return value