- 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 4 years, 9 months ago
- Gravatar support in model save override by JoeLinux 3 years, 2 months ago
- Save image in field by grillermo 4 years, 3 months ago
- is_dirty and dict of changed values by jaredthane 6 years, 8 months ago
- "Approved" field with timestamp by miracle2k 8 years, 9 months ago