lino.mixins.polymorphic

Defines the Polymorphic model mixin. See Multi-table inheritance.

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

Classes

ChildAction(child_model, *args, **kw)

DeleteChild(child_model, *args, **kw)

InsertChild(child_model, *args, **kw)

Polymorphic(*args, **kwargs)

Mixin for models that use Multiple Table Inheritance to implement polymorphism.

class lino.mixins.polymorphic.Polymorphic(*args, **kwargs)

Bases: lino.core.model.Model

Mixin for models that use Multiple Table Inheritance to implement polymorphism.

Subclassed e.g. by lino_xl.lib.contacts.Partner: the recipient of an invoice can be a person, a company, a client, a job provider, an employee..., and a given partner can be both a person and an employee at the same time.

Note that not every usage of Multiple Table Inheritance means polymorphism. For example lino_xl.lib.ledger.models.Voucher has a pointer to the journal which knows which specialization to use, so a given voucher has always exactly one specialization.

mti_navigator

A virtual field which defines buttons for switching between the different views.

Usage examples in Multi-table inheritance and A Local Exchange Trade System.

get_mti_child(*args)

Return the specified specialization or None.

For example if you have two models Place(Model) and Restaurant(Place) and a Place instance p which is not also a Restaurant, then p.get_mti_child('restaurant') will return None.

disable_delete(ar=None)

Overrides lino.core.model.Model.disable_delete().

In case of polymorphy, the user can ask to delete any MTI instance of a polymorphic entity. Deleting one instance will delete all other instances as well.

Before deleting one polymorphic instance, we ask all other instances for their vetos.

Cascade-related objects are deleted independently of the instance that initiated deletion.