How to determine if a field has changed in a Django modelform
问题 I was surprised that this was difficult to do. However I came up with this, which seems to work at least for my simple case. Can anyone recommend a better approach? def field_changed(self, fieldname): """Tests if the value of the field changed from the original data""" orig_value = self.fields[fieldname].initial or getattr(self.instance, field, None) orig_value = getattr(orig_value, 'pk', orig_value) if type(orig_value) is bool: # because None and False can be interchangeable return bool(self