- May 26, 2010
- save field change check
- 3 (after 3 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 5 years ago
- Gravatar support in model save override by JoeLinux 3 years, 6 months ago
- Save image in field by grillermo 4 years, 7 months ago
- is_dirty and dict of changed values by jaredthane 7 years ago
- "Approved" field with timestamp by miracle2k 9 years, 1 month ago