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

  • django/db/models/manipulators.py

     
    109109        if self.change:
    110110            self.fields_added, self.fields_changed, self.fields_deleted = [], [], []
    111111            for f in self.opts.fields:
    112                 if not f.primary_key and str(getattr(self.original_object, f.attname)) != str(getattr(new_object, f.attname)):
     112                if f.primary_key or getattr(f, 'auto_now', None) \
     113                                 or getattr(f, 'auto_now_add', None):
     114                    continue
     115                newval = getattr(new_object, f.attname)
     116                if type(newval) is bool:
     117                    cast = bool
     118                else:
     119                    cast = str
     120                if cast(getattr(self.original_object, f.attname)) != cast(newval):
    113121                    self.fields_changed.append(f.verbose_name)
    114122
    115123        # Save many-to-many objects. Example: Set sites for a poll.
Back to Top