Last active
March 5, 2019 21:47
-
-
Save charlwillia6/512fee1dce086bc90f2d1fe1cfc08f33 to your computer and use it in GitHub Desktop.
Field Change - Check if a field has changed before saving a model. #django #python #view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def has_changed(instance, field): | |
if not instance.pk: | |
return False | |
old_value = instance.__class__._default_manager.filter(pk=instance.pk).values(field).get()[field] | |
return not getattr(instance, field) == old_value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment