Check If a Field Has Changed

1
2
3
4
5
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

More like this

  1. Update timestamp If any instance field has changed by craigruks 1 year, 9 months ago
  2. Improved Pickled Object Field by taavi223 3 years, 9 months ago
  3. Gravatar support in model save override by JoeLinux 3 months ago
  4. check if form has changed (deprecated) by guettli 5 years, 2 months ago
  5. Django Dictionary Model by Morgul 1 year, 11 months ago

Comments

(Forgotten your password?)