Skip to main content

Topics - Entity selection fields

New in v13.0.0

EntityOptionField and EntityMultiSelectField can be used for selecting entities of given type. This will greatly improve the speed of apps where option fields are dynamically filled with entities.

For the selection of an Entity object, dedicated input fields can be used:

When the user selects an entity with these fields, the entity will return in the params as Entity object. Please have a look at sharing information between entities for more detail on how to use an Entity.

Child / Sibling entity selection

For example, when the entity type structure of your application looks similar to the following and you need your users to select one of the child entities of a Project, the ChildEntityOptionField can be used:

└── Project
└── CPTFile
from viktor.parametrization import ViktorParametrization, ChildEntityOptionField

class ProjectParametrization(ViktorParametrization):
selected_cpt = ChildEntityOptionField('Select a CPT')

In case multiple entities should be selectable, the ChildEntityMultiSelectField can be used. Similarly, siblings entities can be selected by using the SiblingEntityOptionField.

Generic entity selection

In some cases, both the ChildEntityOptionField and SiblingEntityOptionField may not be sufficient because the entities you need to select are in a different part of the entity type tree. In the following example, we want to select a CPTFile entity in the Foundation entity type:

└── Project
├── CPTFolder
│ └── CPTFile
└── Foundation

We can make use of the EntityOptionField and the entity_type_names attribute to filter which entity type(s) should be selectable:

from viktor.parametrization import ViktorParametrization, EntityOptionField

class FoundationParametrization(ViktorParametrization):
selected_cpt = EntityOptionField('CPT File', entity_type_names=['CPTFile'])

Or use the EntityMultiSelectField when multiple entities should be selected: