- May 26, 2010
- save field change check
- 2 (after 2 ratings)
Used to check if a field of an object has changed.
This is probably most useful in the save method.
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
- Update timestamp If any instance field has changed by craigruks 3 years, 9 months ago
- Gravatar support in model save override by JoeLinux 2 years, 3 months ago
- Save image in field by grillermo 3 years, 4 months ago
- is_dirty and dict of changed values by jaredthane 5 years, 9 months ago
- "Approved" field with timestamp by miracle2k 7 years, 10 months ago