Overriding virtual fieldsΒΆ

While it is okay to override a database field by a virtual field, the opposite is not true. To avoid this pitfall, Lino raises a ChangedAPI exception when this happens.

It is not allowed to override a virtual field inherited from a parent by a database field. Django doesn't know about Lino's virtual fields and doesn't complain, but when you then try to get the value of the database field, Python will call the virtual field method and give you this value.

The lino_book.projects.ovfields demo application shows this by defining the following database model:

from lino.api import dd, _
from lino.mixins.ref import Referrable

class MyMixin(dd.Model):

    class Meta:
        abstract = True

    def foo(self, ar):
        return str(self) + "!"

class MyModel(MyMixin):

    foo = dd.CharField(
        _("Foo"), max_length=200, blank=True)

>>> from lino import startup
>>> startup('lino_book.projects.ovfields.settings')
Traceback (most recent call last):
lino.core.exceptions.ChangedAPI: CharField field ovfields.MyModel.foo hidden by virtual field of same name.