Filter

Base class: Part

Class that describes a filter that you can search for.

See Query for more complete examples.

Parameters with the prefix field__ will be passed along downstream to the Field instance if applicable. This can be used to tweak the basic style interface.

Refinable members

after     (evaluated)

Type: int | str

See after

assets

Type: Namespace

See assets

attr     (evaluated)

See attr

Cookbook:

How do I control what Q is produced?

choices     (evaluated)

Cookbook:

How do I configure a filter’s GUI field?

config_from_model

Type: Namespace

endpoints

Type: Namespace

extra

Type: dict[str, Any]

See extra

extra_evaluated

Type: dict[str, Any]

See extra

extra_params

field

Type: Namespace

Cookbook:

How do I configure a filter’s GUI field?

freetext     (evaluated)

Cookbook:

How do I make a freetext search field?

include     (evaluated)

Type: bool

See include

Cookbook:

How do I enable searching/filter on columns?

iommi_style

Type: str | Style | None

is_valid_filter

Default: iommi.query.default_filter__is_valid_filter

Cookbook:

How do I customize how a single filter matches?

model     (evaluated)

Type: type[Model] | None

Cookbook:

How do I customize how a single filter matches?

model_field

Cookbook:

How do I customize how a single filter matches?

model_field_name

Cookbook:

How do I customize how a single filter matches?

parse

Cookbook:

How do I customize how a single filter matches?

pk_lookup_to_q

Cookbook:

How do I customize how a single filter matches?

query_name     (evaluated)

Default: lambda filter, **_: filter.iommi_name()

Cookbook:

How do I control what Q is produced?

query_operator_for_field     (evaluated)

Type: str

Default: =

Cookbook:

How do I customize how a single filter matches?

query_operator_to_q_operator

Cookbook:

How do I override what operator is used for a query?

search_fields

Cookbook:

How do I configure a filter’s GUI field?

unary

Cookbook:

How do I customize how a single filter matches?

value_to_q

Cookbook:

How do I control what Q is produced?

Shortcuts

Filter.boolean

Defaults

  • field__call_target__attribute
    • boolean

  • parse
    • iommi.form.bool_parse

  • unary
    • True

  • query_operator_to_q_operator
    • iommi.query.boolean__query_operator_to_q_operator

Filter.boolean_tristate

Defaults

  • field__call_target__attribute
    • boolean_tristate

  • parse
    • iommi.form.boolean_tristate__parse

  • query_operator_to_q_operator
    • iommi.query.boolean__query_operator_to_q_operator

  • unary
    • True

Filter.case_sensitive

Defaults

  • query_operator_to_q_operator
    • iommi.query.case_sensitive_query_operator_to_q_operator

Filter.choice

Field that has one value out of a set.

Defaults

  • field__call_target__attribute
    • choice

Filter.choice_queryset

Field that has one value out of a set.

Defaults

  • field__call_target__attribute
    • choice_queryset

  • query_operator_to_q_operator
    • lambda op: 'exact'

  • value_to_q
    • iommi.query.choice_queryset_value_to_q

  • is_valid_filter
    • iommi.query.choice_queryset__is_valid_filter

Filter.date

Defaults

  • field__call_target__attribute
    • date

  • parse
    • iommi.form.date_parse

Filter.datetime

Defaults

  • field__call_target__attribute
    • date

  • parse
    • iommi.form.date_parse

  • extra_evaluated__is_tz_aware
    • lambda **_: settings.USE_TZ

Filter.decimal

Parent: Filter.number

Defaults

  • field__call_target__attribute
    • decimal

Filter.duration

Parent: Filter.text

Defaults

  • field__call_target__attribute
    • duration

Filter.email

Defaults

  • field__call_target__attribute
    • email

Filter.file

Defaults

  • field__call_target__attribute
    • file

Filter.float

Parent: Filter.number

Defaults

  • field__call_target__attribute
    • float

  • parse
    • iommi.form.float_parse

Filter.foreign_key

Filter.foreign_key_reverse

Defaults

  • field__call_target__attribute
    • foreign_key_reverse

  • extra__django_related_field
    • True

Filter.integer

Parent: Filter.number

Defaults

  • field__call_target__attribute
    • integer

  • parse
    • iommi.form.int_parse

Filter.many_to_many

Filter.many_to_many_reverse

Filter.multi_choice

Field that has one value out of a set.

Defaults

  • field__call_target__attribute
    • multi_choice

Filter.multi_choice_queryset

Defaults

  • field__call_target__attribute
    • multi_choice_queryset

Cookbook:

How do I let a filter match several values at once?

Filter.number

Defaults

  • field__call_target__attribute
    • number

  • query_operator_to_q_operator
    • iommi.query.case_sensitive_query_operator_to_q_operator

Filter.text

Defaults

  • field__call_target__attribute
    • text

  • query_operator_for_field
    • :

Filter.textarea

Parent: Filter.text

Filter.time

Defaults

  • field__call_target__attribute
    • time

  • parse
    • iommi.form.time_parse

Filter.url

Defaults

  • field__call_target__attribute
    • url

Methods

on_bind

on_refine_done

own_evaluate_parameters

Class methods

checkboxes

from_model

Create a Filter from a Django model field.

When used declaratively inside a Query, you normally don’t need to pass anything: the model is taken from the containing query and the model field name from the filter’s own name. This works because resolution is deferred until the query is bound, by which point both are known.

class AlbumQuery(Query):
    name = Filter.from_model()

Pass attr (using __ to drill down) to read a field from a related model:

class AlbumQuery(Query):
    artist_name = Filter.from_model(attr='artist__name')

The explicit model, model_field_name and model_field parameters are still accepted for the rare cases where the field can’t be inferred from context (e.g. when not declared on a query), but are no longer required.