Welcome | Get started | Dive into Lino | Contribute | Reference
Lino core utilities¶
This document tests some functionality of lino.core.utils
.
This is a tested document. The following instructions are used for initialization:
>>> import lino
>>> lino.startup('lino_book.projects.min2.settings.demo')
>>> from lino.api.doctest import *
Get installed models that are subclass of something¶
The lino.core.utils.models_by_base()
function returns a list of
models which are subclass of a given class.
For example here is how you can get all your models that implement
lino.mixins.duplicable.Duplicable
:
>>> from lino.mixins.duplicable import Duplicable
>>> pprint(rt.models_by_base(Duplicable))
[<class 'lino_xl.lib.cal.models.Event'>,
<class 'lino_xl.lib.cal.models.EventType'>,
<class 'lino_xl.lib.cal.models.RemoteCalendar'>,
<class 'lino_xl.lib.contacts.models.Company'>,
<class 'lino_xl.lib.contacts.models.Partner'>,
<class 'lino_xl.lib.contacts.models.Person'>,
<class 'lino_xl.lib.countries.models.Place'>]
>>> rt.models_by_base(rt.models.contacts.Person)
[<class 'lino_xl.lib.contacts.models.Person'>]
Getting only top-level models
The toplevel_only option is used by lino.modlib.checkdata
.
For example the
AddressOwnerChecker
needs to run only on
Partner, not also on Person, Company, Household or any other MTI children.
>>> rt.models_by_base(rt.models.contacts.Partner, toplevel_only=True)
[<class 'lino_xl.lib.contacts.models.Partner'>]
>>> rt.models_by_base(rt.models.contacts.Person, toplevel_only=True)
[<class 'lino_xl.lib.contacts.models.Person'>]