Models¶
Recording Functions¶
-
record_changeset([**kwargs])¶ Return a context manager which records all changes made into a
ChangeSet. If any keyword arguments are give, they are passed toChangeSetwhen it is created as the context manager exits.
-
start_recording([**kwargs])¶ This, coupled with
stop_recording, work the same asrecord_changeset. It is important to ensure thatstop_recordingis called (e.g. in afinallyclause) or the changeset will never be created.
-
stop_recording()¶ See
start_recording
-
scan(objects[, delete_only=False])¶ This must be called during recording (e.g. within
record_changeset).It scans a group of objects for changes after they have been made, and is ideal for situations where recorder cannot track the changes as they are made, or for populating initial data.
objects can be the name of a django app, a django
Model, aModelinstance, or an iterable of any of these. Deleted instances can be included and will be identified as such by their lack of primary key. If delete_only isTrue, then the objects will only be scanned for deleted objects. This is useful when, for example,bulk_deletehas just been used.
Object wrapper¶
One of the fundamental concepts of this app is that the original models should
always be an accurate representation of the current data state. The
main implication of this is that deleted records should actually be
deleted, so a query of MyModel.objects.all() doesn’t return an deleted
or inaccurate data. However, it is useful to maintain a history of deleted
records and historical foreign keys may refer to deleted records, so every
reference to a record is wrapped in by the ObjectWrapper model.
-
class
ObjectWrapper¶ A
GenericForeignKeyis used to reference the instance, so the usual caveats regarding these apply.
A custom manager provides a wrap method, to easily
create new ObjectWrappers.
-
ObjectWrapperManager.wrap(instance)¶ Return an
ObjectWrapperwrapping instance. This is functionally similar toget_or_create.
Field types¶
Individual changes to an instance are stored by field. To properly manage
this, a FieldType model is used. It is similar in concept to ContentType,
but operates at field level instead.
-
class
FieldType¶ A
FieldTypeis identified by the model (via a foreign key toContentType) and the field_name. Additionally, for relation fields, the related model is automatically captured in rel_content_type.-
model¶ Return the model containing the field.
-
field¶ Return the actual field object (e.g. a
CharFieldinstance).
-
clean_value(value)¶ Return a cleaned value using
field.clean. If the value is invalid,ValidationErrorwill be raise.
-
A custom manager is used to provide additional features.
-
class
FieldTypeManager¶ -
for_field(model, field_name)¶ Get a
FieldTypefor the specified model and field name. If the field does not exist on the model,FieldDoesNotExistis raised.
-
get_by_model(model[, related=True])¶ Filter all
FieldTypesby model. If related isTrue, the fields on other models with a foreign or many-to-many key pointing to model will be included.
-
Changesets¶
-
class
ChangeSet¶ -
user¶ The user who made the change. This is a
Userobject from thedjango.contrib.authframework.
-
comment¶ Optional comments related to the changeset. This is stored in a
TextField.
-
Internals¶
-
CHANGE_STATE¶ (('+', 'add'), ('-', 'delete'))The constant defines the choices for
State.stateandM2MChange.change_type.
-
class
State¶ When a record is added or deleted, the change in state is recorded in this model.
-
changeset¶ Return the containing changeset
-
state¶ This indicates if the objects was added or deleted. This is a field defined with choices
CHANGE_STATE, so django provides a way of getting the description viaget_state_display().
-
wrapper¶ The
ObjectWrapperwrapping the instance.
-
instance¶ This property is a shortcut to return
state.wrapper.instance.See also
-
-
class
ValueChange¶ Individual changes are stored in this model.
-
changeset¶ Return the containing changeset
-
wrapper¶ The
ObjectWrapperwrapping the instance.
-
instance¶ This property is a shortcut to return
state.wrapper.instance.See also
-
value¶ Todo
-
-
class
M2MChange¶ This model inherits directly from
ValueChangeand adds a single field.-
change_type¶ This indicates if the object referenced in
valuewas added or deleted. This is a field defined with choicesCHANGE_STATE, so django provides a way of getting the description viaget_change_type_display().
-