Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
Introduction to model mixins¶
Lino comes with a collection of mixin classes for database models that encapsulate higher-level application concepts.
A model mixin is a class meant to mixed into the list of parent classes when
defining a database model. For example lino.mixins.Contactable means
“somebody who can be contacted by email in a given language”. Here is how to use
this model mixin:
class ContactPerson(dd.Model, Contactable):
...
The above ContactPerson model will “automatically” have two fields
email and language. These fields are defined on the
lino.mixins.Contactable mixin.
Here is a list of some model mixins that that are worth to know:
lino.mixins.Contactable: somebody who can be contacted by email in a given languagelino.modlib.printing.Printable: something that can be printedlino.mixins.CreatedModified: adds two read-only timestamp fieldscreatedandmodifiedlino.mixins.periods.DateRange: adds two fieldsstart_dateandend_date.lino.modlib.users.UserAuthored: adds a fielduser, which is automatically set to the user who created a row.lino.mixins.sequenced.Sequenced: adds a fieldseqno, and integer that holds the sequence number of this row among its siblings.lino.modlib.gfks.Controllable: adds a fieldowner, a generic foreign key to some other database row that is considered as its “owner” or “controller”. The exact verbose name for the owner is configurable by the application developer.
That should be enough for an introduction, but I can tell you already now that Lino has many mixins. Some more examples:
lino.modlib.users.Assignablelino.modlib.publisher.Illustratedlino.mixins.periods.DateRangeObservable
See also lino.core.model and lino.mixins.