Jump to >

djblets.db.fields.modification_timestamp_field

Field for managing modification timestamps for a model.

class ModificationState[source]

Modification state for a tracked value.

first_set

Whether or not the next setattr() will be the first.

When this is True, we do not consider the next setattr() to be a modification since the field will be set during model initialization.

Type

bool

modified

Whether or not the value has been manually modified.

Type

bool

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

unicode

class ModificationTrackedValue(field_name, state_name)[source]

A descriptor for tracking the modification of a value.

field_name

The attribute name of the field on the model.

Type

unicode

state_name

The attribute name of the state on the model.

Type

unicode

class ModificationTimestampField(*args, **kwargs)[source]

A timestamp field that only updates existing objects or when None.

This is a subclass of DateTimeField that 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.

contribute_to_class(cls, name)[source]

Contribute the field attributes to the class.

Parameters
  • cls (type) – The model class to contribute the field to.

  • name (unicode) – The name of the field.

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

datetime.datetime