About virtual fields


Define a virtual field on a model:

def bus_needed(self, ar):
    return self.get_places_sum(
        state=EnrolmentStates.requested, needs_bus=True)

(Taken from lino_avanti.lib.avanti.Client)

Define a virtual field on a table:

def question(self, obj, ar):
    return obj

(Taken from lino_xl.lib.polls.PollResult)


Some entries to the API:


  • Write a simple example project in tutorials

Some edge cases

A cool example is in lino_welfare.modlib.pcsw.models where we have:

dd.update_field(Client, 'overview', verbose_name=None)

This is special because Client is abstract at this place1. Abstract models don't have a copy of each inherited virtual field. the overview field is


Note that actually it is abstract only in eupen, not in chatelet. But that's another cool thing.