Code

Ticket #1584: auto_now_add_fix.2.diff

File auto_now_add_fix.2.diff, 546 bytes (added by Andy Dustman <farcepest@…>, 8 years ago)

Better bug fix (evaluation order matters)

Line 
1Index: django/db/models/fields/__init__.py
2===================================================================
3--- django/db/models/fields/__init__.py (revision 2628)
4+++ django/db/models/fields/__init__.py (working copy)
5@@ -423,7 +423,7 @@
6         return Field.get_db_prep_lookup(self, lookup_type, value)
7 
8     def pre_save(self, value, add):
9-        if self.auto_now or (self.auto_now_add and add):
10+        if self.auto_now or (self.auto_now_add and add and not value):
11             return datetime.datetime.now()
12         return value
13