djblets.db.fields.modification_timestamp_field¶
Field for managing modification timestamps for a model.
- class ModificationState[source]¶
- Bases: - object- Modification state for a tracked value. - static get_attr_name(field_name)[source]¶
- Return the attribute name for the state for the named field. - Parameters:
- field_name ( - unicode) – The attribute name of the- ModificationTimestampField.
- Returns:
- The name of the modification state attribute. 
- Return type:
 
 
- class ModificationTrackedValue(field_name, state_name)[source]¶
- Bases: - object- A descriptor for tracking the modification of a value. - __get__(instance, objtype=None)[source]¶
- Return the value. - Parameters:
- instance ( - django.db.models.Model) – The model instance.
- objtype ( - type, optional) – The model class.
 
- Returns:
- The value. 
- Return type:
 
 - __set__(instance, value)[source]¶
- Set the value. - This tracks modifications and sets the modified state if this is not the first call to this method (which occurs during object initialization). - Parameters:
- instance ( - django.db.models.Model) – The instance to set the the value on.
- value ( - datetime.datetime) – The value to set.
 
 
 
- class ModificationTimestampField(*args, **kwargs)[source]¶
- Bases: - DateTimeField- A timestamp field that only updates existing objects or when None. - This is a subclass of - DateTimeFieldthat only auto-updates the timestamp when updating an existing object or when the value of the field is None. It’s similar to using- auto_now=True, but custom timestamp values on new instances will not be replaced.- pre_save(model_instance, add)[source]¶
- Return the value of the field just before saving. - Parameters:
- model_instance ( - django.db.models.Model) – The model instance being saved.
- add ( - bool) – Whether this is being saved to the database for the first time.
 
- Returns:
- The date/time value being saved. 
- Return type:
 
 - __annotations__ = {}¶
 
