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.
| Setting | Type | Default | Description |
|---|---|---|---|
id | str | Required | Stable operator ID stored in filter conditions. |
documentation | str | '' | Markdown and tagged examples included in the generated developer reference. |
label | str | Required | Label shown for this operator in the filter editor. |
expressions | tuple[str, ...] | Required | Django lookup expressions accepted by this operator. |
description | str | None | None | Summary of which values the operator matches. |
nested | bool | False | Whether the operator delegates to a filter on a related model. |
q_factory | Callable[Any, str, str, Any, CompiledLookup] | None | None | Callback that compiles a filter condition to a Django Q object. |
sql_factory | Callable[[SQLLookupContext, str, Any], CompiledSQL] | None | None | Optional callback that compiles the condition for SQL filters. |
python_evaluator | Callable[[Any, Any], bool] | None | None | Optional callback that evaluates the condition against a Python value. |
default_form_factory | Callable[[FilterFieldContext], Field] | None | None | Callback that builds the default operator input. |
nested_fields_factory | Callable[[Type[Model], str], list[Any]] | None | None | Callback 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.
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.
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
| Field | Value |
|---|---|
nested | False |
Contains
ID contains
Matches text containing the supplied value, ignoring case.
| Field | Value |
|---|---|
nested | False |
Count equals
ID count_equals
| Field | Value |
|---|---|
nested | False |
Count greater than
ID count_greater_than
| Field | Value |
|---|---|
nested | False |
Count greater than or equal
ID count_greater_than_or_equal
| Field | Value |
|---|---|
nested | False |
Count less than
ID count_less_than
| Field | Value |
|---|---|
nested | False |
Count less than or equal
ID count_less_than_or_equal
| Field | Value |
|---|---|
nested | False |
Day
ID day
| Field | Value |
|---|---|
nested | False |
Day of week
ID day_of_week
| Field | Value |
|---|---|
nested | False |
Day of week in
ID day_of_week_in
| Field | Value |
|---|---|
nested | False |
Ends with
ID ends_with
Matches values ending with the supplied text.
| Field | Value |
|---|---|
nested | False |
Equals
ID equals
| Field | Value |
|---|---|
nested | False |
Equals Current User
ID equals_user
| Field | Value |
|---|---|
nested | False |
Advanced
ID foreign_advanced
Delegates the remaining lookup path to the related model.
| Field | Value |
|---|---|
nested | True |
Greater than or equal
ID greater_than_or_equal
| Field | Value |
|---|---|
nested | False |
Greater than
ID greater_than
| Field | Value |
|---|---|
nested | False |
Equals (case-insensitive)
ID iexact
Matches text without regard to letter casing.
| Field | Value |
|---|---|
nested | False |
Is null
ID is_null
Matches null values when true and non-null values when false.
| Field | Value |
|---|---|
nested | False |
Key
ID json_key
Select a JSON object key; keys retain JSON value semantics.
| Field | Value |
|---|---|
nested | True |
Last month
ID last_month
| Field | Value |
|---|---|
nested | False |
Last quarter
ID last_quarter
| Field | Value |
|---|---|
nested | False |
Last week
ID last_week
| Field | Value |
|---|---|
nested | False |
Last year
ID last_year
| Field | Value |
|---|---|
nested | False |
Less than or equal
ID less_than_or_equal
| Field | Value |
|---|---|
nested | False |
Less than
ID less_than
| Field | Value |
|---|---|
nested | False |
Month
ID month
| Field | Value |
|---|---|
nested | False |
Does not equal
ID not_equals
| Field | Value |
|---|---|
nested | False |
Not in
ID not_in
| Field | Value |
|---|---|
nested | False |
Advanced
ID one_to_many_advanced
Delegates the remaining lookup path to the related model.
| Field | Value |
|---|---|
nested | True |
Starts with
ID starts_with
Matches values beginning with the supplied text.
| Field | Value |
|---|---|
nested | False |
This month
ID this_month
Matches dates that fall in the current local month.
| Field | Value |
|---|---|
nested | False |
This quarter
ID this_quarter
| Field | Value |
|---|---|
nested | False |
This week
ID this_week
| Field | Value |
|---|---|
nested | False |
This year
ID this_year
| Field | Value |
|---|---|
nested | False |
Today
ID today
Matches dates that fall on the current local day.
| Field | Value |
|---|---|
nested | False |
In
ID values_in
Matches a value against a supplied list of candidates.
| Field | Value |
|---|---|
nested | False |
Week
ID week
| Field | Value |
|---|---|
nested | False |
Year
ID year
| Field | Value |
|---|---|
nested | False |
Yesterday
ID yesterday
| Field | Value |
|---|---|
nested | False |
