Computed fields
Fields can have values calculated by a function, instead of simply reading a database stored value. A computed field is declared just like a regular field, but has the additional compute argument defining the function used to calculate it.
In most cases computed fields involve writing some business logic, so we will develop this topic more in Chapter 7, ORM Application Logic - Supporting Business Processes. We will still explain them here, but will keep the business logic side as simple as possible.
Let's work on an example: Stages have a fold field. We will add to To-do Tasks a computed field with the Folded? flag for the corresponding Stage.
We should edit the TodoTask model in the todo_model.py file to add the following:
# class ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access