Models used by all apps in the project.

class common.models.ApplicabilityCode(*args, **kwargs)[source]

Bases: django.db.models.fields.PositiveSmallIntegerField

deconstruct()[source]

Return enough information to recreate the field as a 4-tuple:

  • The name of the field on the model, if contribute_to_class() has been run.

  • The import path of the field, including the class, e.g. django.db.models.IntegerField. This should be the most portable version, so less specific may be better.

  • A list of positional arguments.

  • A dict of keyword arguments.

Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):

  • None, bool, str, int, float, complex, set, frozenset, list, tuple, dict

  • UUID

  • datetime.datetime (naive), datetime.date

  • top-level classes, top-level functions - will be referenced by their full import path

  • Storage instances - these have their own deconstruct() method

This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.

There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.

class common.models.DescriptionMixin(*args, **kwargs)[source]

Bases: common.models.mixins.validity.ValidityStartMixin

class Meta[source]

Bases: object

abstract = False
business_rules = (<class 'common.business_rules.NoBlankDescription'>, <class 'common.business_rules.UniqueIdentifyingFields'>, <class 'common.business_rules.UpdateValidity'>)
class property described_object_field: django.db.models.fields.Field
get_described_object()[source]
get_next_by_validity_start(*, field=<django.db.models.fields.DateField: validity_start>, is_next=True, **kwargs)
get_previous_by_validity_start(*, field=<django.db.models.fields.DateField: validity_start>, is_next=False, **kwargs)
get_url(action='detail')[source]
objects: common.models.mixins.validity.ValidityStartQueryset

The with_end_date() method is used to automatically compute the end date based on the other models in the series.

class property validity_over
validity_start

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class common.models.NumericSID(*args, **kwargs)[source]

Bases: django.db.models.fields.PositiveIntegerField

deconstruct()[source]

Return enough information to recreate the field as a 4-tuple:

  • The name of the field on the model, if contribute_to_class() has been run.

  • The import path of the field, including the class, e.g. django.db.models.IntegerField. This should be the most portable version, so less specific may be better.

  • A list of positional arguments.

  • A dict of keyword arguments.

Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):

  • None, bool, str, int, float, complex, set, frozenset, list, tuple, dict

  • UUID

  • datetime.datetime (naive), datetime.date

  • top-level classes, top-level functions - will be referenced by their full import path

  • Storage instances - these have their own deconstruct() method

This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.

There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.

class common.models.ShortDescription(*args, **kwargs)[source]

Bases: django.db.models.fields.CharField

deconstruct()[source]

Return enough information to recreate the field as a 4-tuple:

  • The name of the field on the model, if contribute_to_class() has been run.

  • The import path of the field, including the class, e.g. django.db.models.IntegerField. This should be the most portable version, so less specific may be better.

  • A list of positional arguments.

  • A dict of keyword arguments.

Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):

  • None, bool, str, int, float, complex, set, frozenset, list, tuple, dict

  • UUID

  • datetime.datetime (naive), datetime.date

  • top-level classes, top-level functions - will be referenced by their full import path

  • Storage instances - these have their own deconstruct() method

This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.

There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.

class common.models.SignedIntSID(*args, **kwargs)[source]

Bases: django.db.models.fields.IntegerField

deconstruct()[source]

Return enough information to recreate the field as a 4-tuple:

  • The name of the field on the model, if contribute_to_class() has been run.

  • The import path of the field, including the class, e.g. django.db.models.IntegerField. This should be the most portable version, so less specific may be better.

  • A list of positional arguments.

  • A dict of keyword arguments.

Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):

  • None, bool, str, int, float, complex, set, frozenset, list, tuple, dict

  • UUID

  • datetime.datetime (naive), datetime.date

  • top-level classes, top-level functions - will be referenced by their full import path

  • Storage instances - these have their own deconstruct() method

This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.

There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.

class common.models.TimestampedMixin(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Mixin adding timestamps for creation and last update.

class Meta[source]

Bases: object

abstract = False
created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)
updated_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class common.models.TrackedModel(id, polymorphic_ctype, created_at, updated_at, transaction, update_type, version_group)[source]

Bases: polymorphic.models.PolymorphicModel, common.models.mixins.TimestampedMixin

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

additionalcode

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

additionalcodedescription

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

additionalcodetype

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

additionalcodetypemeasuretype

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

amendment

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

class property auto_value_fields: Set[django.db.models.fields.Field]

Returns the set of fields on this model that should have their value set automatically on save, excluding any primary keys.

business_rules: Iterable = ()
certificate

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

certificatedescription

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

certificatetype

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

checks

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

copy(transaction, **overrides: Any) common.models.trackedmodel.Cls[source]

Create a copy of the model as a new logical domain object – i.e. with a new version group, new SID (if present) and update type of CREATE.

Any dependent models that are TARIC subrecords of this model will be copied as well. Any many-to-many relationships will also be duplicated if they do not have an explicit through model. Any overrides passed in as keyword arguments will be applied to the new model. If the model uses SIDs, they will be automatically set to the next highest available SID. Models with other identifying fields should have thier new IDs passed in through overrides.

class property copyable_fields

Return the set of fields that can have their values copied from one model to another. This is anything that is:

  • a native value

  • a foreign key to some other model

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

current_objects: common.models.tracked_qs.TrackedModelQuerySet = <django.db.models.manager.CurrentTrackedModelManagerFromTrackedModelQuerySet object>

The current_objects model manager provides a default queryset that, by default, filters to the ‘current’ transaction.

property current_version: common.models.trackedmodel.Cls

The current version of this model.

dutyexpression

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

extension

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

footnote

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

footnoteassociationadditionalcode

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

footnoteassociationgoodsnomenclature

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

footnoteassociationmeasure

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

footnotedescription

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

footnotetype

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

geographicalarea

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

geographicalareadescription

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

geographicalmembership

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

get_identifying_fields(identifying_fields: Optional[Iterable[str]] = None) Dict[str, Any][source]

Get a name/value mapping of the fields that identify this model.

Parameters

Optional[Iterable[str]] (identifying_fields) – Optionally override

the fields to retrieve :rtype dict[str, Any]: A dict of field names to values

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)
get_update_type_display(*, field=<django.db.models.fields.PositiveSmallIntegerField: update_type>)
get_url(action: str = 'detail') Optional[str][source]

Generate a URL to a representation of the model in the webapp.

Callers should handle the case where no URL is returned.

Parameters

str (action) – The view type to generate a URL for (default “detail”), eg: “list” or “edit” :rtype Optional[str]: The generated URL

classmethod get_url_pattern_name_prefix()[source]

Get the prefix string for a view name for this model.

By default, this is the verbose name of the model with spaces replaced by underscores, but this method allows this to be overridden.

Rtype str

The prefix

get_versions()[source]

Find all versions of this model.

goodsnomenclature

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

goodsnomenclaturedescription

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

goodsnomenclatureindent

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

goodsnomenclatureorigin

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

goodsnomenclaturesuccessor

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

group

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

identifying_fields: Sequence[str] = ('pk',)

The fields which together form a composite unique key for each model.

The system ID (or SID) field, ‘sid’ is normally the unique identifier of a TARIC model, but in places where this does not exist models can declare their own. (Note that because multiple versions of each model will exist this does not actually equate to a UNIQUE constraint in the database.)

TrackedModel itself defaults to (“pk”,) as it does not have an SID.

identifying_fields_to_string(identifying_fields: Optional[Iterable[str]] = None) str[source]

Constructs a comma separated string of the identifying fields of the model with field name and value pairs delimited by “=”, eg: “field1=1, field2=2”.

Parameters

identifying_fields – Optionally override the fields to use in the string

Rtype str

The constructed string

in_use(transaction=None, *relations: str) bool[source]

Returns True if there are any models that are using this one as of the specified transaction.

This can be any model this model is related to, but ignoring any subrecords (because e.g. a footnote is not considered “in use by” its own description) and then filtering for only things that link _to_ this model.

The list of relations can be filtered by passing in the name of a relation. If a name is passed in that does not refer to a relation on this model, ValueError will be raised.

in_use_by(via_relation: str, transaction=None) django.db.models.query.QuerySet[source]

Returns all of the models that are referencing this one via the specified relation and exist as of the passed transaction.

via_relation should be the name of a relation, and a KeyError will be raised if the relation name is not valid for this model. Relations are accessible via get_relations helper method.

indirect_business_rules: Iterable = ()
measure

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

measureaction

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

measurecomponent

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

measurecondition

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

measureconditioncode

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

measureconditioncomponent

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

measureexcludedgeographicalarea

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

measurement

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

measurementunit

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

measurementunitqualifier

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

measuretype

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

measuretypeseries

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

monetaryunit

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

new_version(workbasket, transaction=None, update_type: common.validators.UpdateType = UpdateType.UPDATE, **overrides) common.models.trackedmodel.Cls[source]

Create and return a new version of the object. Callers can override existing data by passing in keyword args.

The new version is added to a transaction which is created and added to the passed in workbasket (or may be supplied as a keyword arg).

update_type must be UPDATE or DELETE, with UPDATE as the default.

objects: common.models.tracked_qs.TrackedModelQuerySet = <django.db.models.manager.TrackedModelManagerFromTrackedModelQuerySet object>
polymorphic_ctype

The model field that stores the ContentType reference to the actual class.

polymorphic_ctype_id
polymorphic_primary_key_name = 'id'
polymorphic_super_sub_accessors_replaced = False
quotaassociation

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

quotablocking

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

quotadefinition

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

quotaevent

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

quotaordernumber

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

quotaordernumberorigin

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

quotaordernumberoriginexclusion

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

quotasuspension

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

record_code: int

The type id of this model’s type family in the TARIC specification.

This number groups together a number of different models into ‘records’. Where two models share a record code, they are conceptually expressing different properties of the same logical model.

In theory each Transaction should only contain models with a single record_code (but differing subrecord_code.)

property record_identifier: str

Returns the record identifier as defined in TARIC3 records specification.

regulation

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

replacement

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

save(*args, force_write=False, **kwargs)[source]

Save the model to the database.

Parameters

bool (force_write) – Ignore append-only restrictions and write to the database even if the model already exists

property structure_code

A string used to describe the model instance.

Used as the displayed value in an AutocompleteWidget dropdown, and in the “Your tariff changes” list.

property structure_description: Optional[str]

The current description of the model, if it has related description models or a description field.

Rtype Optional[str]

The current description

subrecord_code: int

The type id of this model in the TARIC specification. The subrecord_code when combined with the record_code uniquely identifies the type within the specification.

The subrecord code gives the intended order for models in a transaction, with comparatively smaller subrecord codes needing to come before larger ones.

suspension

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

system_set_field_names = {'created_at', 'id', 'is_current', 'polymorphic_ctype', 'trackedmodel_ptr', 'transaction', 'update_type', 'updated_at', 'version_group'}
termination

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

testmodel1

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

testmodel2

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

testmodel3

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

testmodeldescription1

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

transaction

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

transaction_id
transactioncheck_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

update_type: common.validators.UpdateType

The change that was made to the model when this version of the model was authored.

The first version should always have CREATE, subsequent versions will have UPDATE and the final version will have DELETE. Deleted models that reappear for the same identifying_fields will have a new version_group created.

property update_type_str: str
updated_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

url_suffix = ''

This is to add a link within a page for get_url() e.g. for linking to a Measure’s conditions tab.

If url_suffix is set to ‘#conditions’ the output detail url will be /measures/12345678/#conditions

version_at(transaction) common.models.trackedmodel.Cls[source]

The latest version of this model that was approved as of the given transaction.

Parameters

Transaction (transaction) – Limit versions to this transaction

Rtype TrackedModel

version_group: common.models.trackedmodel.VersionGroup

Each version group contains all of the versions of the same logical model.

When a new version of a model is authored (e.g. to DELETE it) a new model row is created and added to the same version group as the existing model being changed.

Models are identified logically by their identifying_fields, so within one version group all of the models should have the same values for these fields.

version_group_id
versiongroup

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

class common.models.Transaction(*args, **kwargs)[source]

Bases: common.models.mixins.TimestampedMixin

Contains a group of one or more TrackedModel instances that must be applied atomically.

Linked to a WorkBasket and may be contained by one or more Envelopes when exported.

Business rule validation is performed at Transaction level for creates, updates and deletes. Business rules are also validated at the TrackedModel level for creates.

Mutation rules:

Only transactions in the DRAFT partition should be modified - at that point they may be moved to SEED_FILE or REVISION partitions, and the order field will be updated.

Transactions in SEED_FILE or REVISION partitions should not be modified.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

add_to_transaction(instance, **kwargs)[source]
approved = <django.db.models.manager.ApprovedTransactionManagerFromTransactionQueryset object>
checks

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

composite_key

Originally containing workbasket pk, order and partition for user created transactions.

Now a random unique string to avoid duplicate values when reordering / deleting transactions.

It is not clear what the purpose of composite_key is other than as an application level unique ID for a transaction. It is not used anywhere in the app.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

envelopes

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

envelopetransaction_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

get_all_partition_transitions(*, field=<django_fsm.FSMIntegerField: partition>)
get_available_partition_transitions(*, field=<django_fsm.FSMIntegerField: partition>)
get_available_user_partition_transitions(user, *, field=<django_fsm.FSMIntegerField: partition>)
get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)
get_partition_display(*, field=<django_fsm.FSMIntegerField: partition>)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

import_transaction_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.TransactionManagerFromTransactionQueryset object>
order

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

partition
save_draft(partition_scheme)[source]

Finalise a single DRAFT transaction as a REVISION.

Delegates to Transaction.objects.save_drafts() which is a better choice if updating many records.

property summary

Return a short summary of the transaction.

Attempts a balance between readability and enough information to debug issues, so contains the partion, order for transactions and pk, status for workbaskets.

Stringification happens lazily so this property is suitable for use when logging.

to_json()[source]

Serialize to JSON.

Used for storing in the session.

tracked_models

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

transactioncheck_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

transactiongroup_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

updated_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

workbasket

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

workbasket_id
class common.models.User(*args, **kwargs)[source]

Bases: django.contrib.auth.models.AbstractUser

Custom user model.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

approved_workbaskets

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

assigned_by

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

assigned_to

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

authored_comments

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

crowndependenciespublishingoperationalstatus_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

current_workbasket

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

current_workbasket_id
date_joined

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

email

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

first_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_displayname()[source]

Best effort at getting a useful representation of a User’s name for general display purposes.

get_next_by_date_joined(*, field=<django.db.models.fields.DateTimeField: date_joined>, is_next=True, **kwargs)
get_previous_by_date_joined(*, field=<django.db.models.fields.DateTimeField: date_joined>, is_next=False, **kwargs)
groups

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

importbatch_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

is_active

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_staff

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_superuser

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_login

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

logentry_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

measuresbulkcreator_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

measuresbulkeditor_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

operationalstatus_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

password

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

remove_current_workbasket()[source]

Remove the user’s assigned current workbasket.

sso_uuid

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user_permissions

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

username

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

workbasket_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class common.models.ValidityMixin(*args, **kwargs)[source]

Bases: django.db.models.base.Model

The model is live after the validity start date (valid_between.lower) and before the validity end date (valid_between.upper).

Start and end validity dates are inclusive – meaning that the model is live from the beginning of the start date to the end of the end date. A model with the same start and end date is therefore live for 1 day. If the validity end date is blank (valid_between.upper_inf) then the model is live indefinitely after the start date.

Validity dates can be modified with a new version of a model, so a model that initially has a blank end date can be updated to subsequently add one.

class Meta[source]

Bases: object

abstract = False
terminate(workbasket, when: datetime.date) common.models.mixins.validity.Self[source]

Returns a new version of the object updated to end on the specified date.

If the object would not have started on that date, the object is deleted instead. If the object will already have ended by this date, then does nothing.

Any keyword arguments passed will be applied in the case of an update and are ignored for a delete or no change.

valid_between

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

validity_field_name: str = 'valid_between'

The name of the field that should be used for validity date checking.

class common.models.ValidityStartMixin(*args, **kwargs)[source]

Bases: django.db.models.base.Model

The model is live after the validity_start date and before the validity_start date of the next model in the same series.

This is broadly the same as the ValidityMixin but the lack of an end date enforces that there is always one model of this type active at any one time for a given series.

This validity method is used when this model tracks some time-varying property of a related model. For example, this model may carry a description of the related model, and the description can be updated independently of the related model. The “series” is then defined by identifing_fields of the related model, such that for each related model there can be multiple of this model, each with their own validity period.

Start and end validity dates are inclusive – meaning that the model is live from the beginning of the start date to the end of the end date. A model with the same start and end date is therefore live for 1 day. If the validity end date is blank then the model is live indefinitely after the start date.

class Meta[source]

Bases: object

abstract = False
get_next_by_validity_start(*, field=<django.db.models.fields.DateField: validity_start>, is_next=True, **kwargs)
get_previous_by_validity_start(*, field=<django.db.models.fields.DateField: validity_start>, is_next=False, **kwargs)
objects: common.models.mixins.validity.ValidityStartQueryset

The with_end_date() method is used to automatically compute the end date based on the other models in the series.

validity_over: str

Models with a single validity date always represent some feature of a related model and are only live for as long as that model is live.

The is the name of the field on this model that is a foreign key to the related model. E.g. for a description it is the described model.

validity_start

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class common.models.VersionGroup(*args, **kwargs)[source]

Bases: common.models.mixins.TimestampedMixin

A group that contains all versions of the same TrackedModel.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

current_version

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

current_version_id
get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
updated_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

versions: django.db.models.query.QuerySet

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

Submodules

trackedmodel

tracked_utils

tracked_qs

transactions

Transaction model and manager.

dc

mixins

Mixins for models.

constants

Includes constants and enumerators for use in orm models.