lino.mixins.ref

Defines the Referrable model mixin.

(This module's source code is available here.)

Classes

Referrable(*args, **kwargs)

Mixin for things that have a unique reference, i.e.

StructuredReferrable(*args, **kwargs)

A referrable whose ref field is used to define a hierarchical structure.

class lino.mixins.ref.Referrable(*args, **kwargs)

Bases: lino.core.model.Model

Mixin for things that have a unique reference, i.e. an identifying name used by humans to refer to an individual object.

A reference, unlike a primary key, can easily be changed.

Referrable objects are mergeable by default.

ref

The reference. This must be either empty or unique.

ref_max_length = 40

The preferred width of the ref field.

TODO: rename this to preferred_ref_width.

on_duplicate(ar, master)

Before saving a duplicated object for the first time, we must change the ref in order to avoid an IntegrityError.

classmethod get_by_ref(ref, default=<class 'django.db.models.fields.NOT_PROVIDED'>)

Return the object identified by the given reference.

classmethod quick_search_filter(search_text, prefix='')

Overrides the default behaviour defined in lino.core.model.Model.quick_search_filter(). For Referrable objects, when quick-searching for a text containing only digits, the user usually means the ref and not the primary key.

class lino.mixins.ref.StructuredReferrable(*args, **kwargs)

Bases: lino.mixins.ref.Referrable

A referrable whose ref field is used to define a hierarchical structure.

Example:

1       Foos
 10     Good foos
   1000 Nice foos
   1020 Obedient foos
 11     Bad foos
   1100 Nasty foo
   1110 Lazy foo
2       Bars
   2000 Normal bars
   2090 Other bars

The length of the reference determines the hierarchic level: the shorter it is, the higher the level.

The hierarchic level becomes visible a virtual field ref_description in together with the designation.

ref_description

Displays the structured together with the designation.

The mixin differentiates between "headings" and "leaves": objects whose ref has ref_max_length characters are considered "leaves" while all other objects are "headings".

Subclasses must provide a method get_designation().

get_designation()

Return the "designation" part (without the reference).