Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
lino.mixins.polymorphic¶
Defines the Polymorphic
model mixin.
See Multi-table inheritance.
Classes
|
|
|
|
|
|
|
Mixin for models that use Multiple Table Inheritance to implement polymorphism. |
- class lino.mixins.polymorphic.Polymorphic(*args, **kwargs)¶
Bases:
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.accounting.models.Voucher has a pointer to the journal which knows which specialization to use, so a given voucher has always exactly one specialization.
A virtual field which defines buttons for switching between the different views.
Usage examples in Multi-table inheritance and The LETS tutorial.
- 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
that 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.