Code

Ticket #1511: django_1511.diff

File django_1511.diff, 1.1 KB (added by Christopher Lenz <cmlenz@…>, 8 years ago)

Alternative approach that also ignores auto_now and auto_now_add fields

Line 
1Index: django/db/models/manipulators.py
2===================================================================
3--- django/db/models/manipulators.py    (revision 944)
4+++ django/db/models/manipulators.py    (working copy)
5@@ -109,7 +109,15 @@
6         if self.change:
7             self.fields_added, self.fields_changed, self.fields_deleted = [], [], []
8             for f in self.opts.fields:
9-                if not f.primary_key and str(getattr(self.original_object, f.attname)) != str(getattr(new_object, f.attname)):
10+                if f.primary_key or getattr(f, 'auto_now', None) \
11+                                 or getattr(f, 'auto_now_add', None):
12+                    continue
13+                newval = getattr(new_object, f.attname)
14+                if type(newval) is bool:
15+                    cast = bool
16+                else:
17+                    cast = str
18+                if cast(getattr(self.original_object, f.attname)) != cast(newval):
19                     self.fields_changed.append(f.verbose_name)
20 
21         # Save many-to-many objects. Example: Set sites for a poll.