BloomERP

Built-ins

LookupDefinition

Declare a reusable filter operator and the expressions it supports.

Register the operator by ID. Include it in each field type that should offer it. The default compiler builds a Django ORM filter from the selected expression. Provide a Python evaluator if the operator also needs to match unsaved form values.

SettingTypeDefaultDescription
idstrRequiredStable operator ID stored in filter conditions.
documentationstr''Markdown and tagged examples included in the generated developer reference.
labelstrRequiredLabel shown for this operator in the filter editor.
expressionstuple[str, ...]RequiredDjango lookup expressions accepted by this operator.
descriptionstr | NoneNoneSummary of which values the operator matches.
nestedboolFalseWhether the operator delegates to a filter on a related model.
q_factoryCallable[Any, str, str, Any, CompiledLookup] | NoneNoneCallback that compiles a filter condition to a Django Q object.
sql_factoryCallable[[SQLLookupContext, str, Any], CompiledSQL] | NoneNoneOptional callback that compiles the condition for SQL filters.
python_evaluatorCallable[[Any, Any], bool] | NoneNoneOptional callback that evaluates the condition against a Python value.
default_form_factoryCallable[[FilterFieldContext], Field] | NoneNoneCallback that builds the default operator input.
nested_fields_factoryCallable[[Type[Model], str], list[Any]] | NoneNoneCallback that returns filterable fields for nested conditions.

Register an exact reference lookup

Use Django’s default equality compilation with a label specific to your domain.

python
from bloomerp.lookups.definition import LookupDefinition
from bloomerp.lookups.registry import LOOKUP_REGISTRY

reference_match = LookupDefinition(
    id="example_reference_match",
    label="Reference matches",
    description="Compare the field with the supplied reference.",
    expressions=("exact",),
)
LOOKUP_REGISTRY.register(reference_match.id, reference_match)

Let a lookup match draft form values

Use an evaluator with the same case handling as the database expression.

python
from bloomerp.lookups.definition import LookupDefinition
from bloomerp.lookups.registry import LOOKUP_REGISTRY


def matches_prefix(value: object, expected: object) -> bool:
    '''Match a text prefix without regard to case.'''
    return (
        isinstance(value, str)
        and isinstance(expected, str)
        and value.casefold().startswith(expected.casefold())
    )


prefix = LookupDefinition(
    id="example_reference_prefix",
    label="Starts with reference",
    expressions=("istartswith",),
    python_evaluator=matches_prefix,
)
LOOKUP_REGISTRY.register(prefix.id, prefix)

Contains

ID address_contains

FieldValue
nestedFalse

Contains

ID contains

Matches text containing the supplied value, ignoring case.

FieldValue
nestedFalse

Count equals

ID count_equals

FieldValue
nestedFalse

Count greater than

ID count_greater_than

FieldValue
nestedFalse

Count greater than or equal

ID count_greater_than_or_equal

FieldValue
nestedFalse

Count less than

ID count_less_than

FieldValue
nestedFalse

Count less than or equal

ID count_less_than_or_equal

FieldValue
nestedFalse

Day

ID day

FieldValue
nestedFalse

Day of week

ID day_of_week

FieldValue
nestedFalse

Day of week in

ID day_of_week_in

FieldValue
nestedFalse

Ends with

ID ends_with

Matches values ending with the supplied text.

FieldValue
nestedFalse

Equals

ID equals

FieldValue
nestedFalse

Equals Current User

ID equals_user

FieldValue
nestedFalse

Advanced

ID foreign_advanced

Delegates the remaining lookup path to the related model.

FieldValue
nestedTrue

Greater than or equal

ID greater_than_or_equal

FieldValue
nestedFalse

Greater than

ID greater_than

FieldValue
nestedFalse

Equals (case-insensitive)

ID iexact

Matches text without regard to letter casing.

FieldValue
nestedFalse

Is null

ID is_null

Matches null values when true and non-null values when false.

FieldValue
nestedFalse

Key

ID json_key

Select a JSON object key; keys retain JSON value semantics.

FieldValue
nestedTrue

Last month

ID last_month

FieldValue
nestedFalse

Last quarter

ID last_quarter

FieldValue
nestedFalse

Last week

ID last_week

FieldValue
nestedFalse

Last year

ID last_year

FieldValue
nestedFalse

Less than or equal

ID less_than_or_equal

FieldValue
nestedFalse

Less than

ID less_than

FieldValue
nestedFalse

Month

ID month

FieldValue
nestedFalse

Does not equal

ID not_equals

FieldValue
nestedFalse

Not in

ID not_in

FieldValue
nestedFalse

Advanced

ID one_to_many_advanced

Delegates the remaining lookup path to the related model.

FieldValue
nestedTrue

Starts with

ID starts_with

Matches values beginning with the supplied text.

FieldValue
nestedFalse

This month

ID this_month

Matches dates that fall in the current local month.

FieldValue
nestedFalse

This quarter

ID this_quarter

FieldValue
nestedFalse

This week

ID this_week

FieldValue
nestedFalse

This year

ID this_year

FieldValue
nestedFalse

Today

ID today

Matches dates that fall on the current local day.

FieldValue
nestedFalse

In

ID values_in

Matches a value against a supplied list of candidates.

FieldValue
nestedFalse

Week

ID week

FieldValue
nestedFalse

Year

ID year

FieldValue
nestedFalse

Yesterday

ID yesterday

FieldValue
nestedFalse