mirror of
https://github.com/Hopiu/django-model-utils.git
synced 2026-03-16 20:00:23 +00:00
Implemented ability to change modified fields manually.
This commit is contained in:
parent
500dd470cd
commit
e353a01a9a
1 changed files with 8 additions and 2 deletions
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue