API reference¶
Lookups¶
- izaya.register(lookup: T) T¶
Make a lookup reachable through the search endpoint.
- class izaya.Lookup¶
Base class for lookups over any data source.
Subclasses implement
searchandget_selected. Both return a sequence of results thatto_itemunderstands, which by default means(key, label)pairs.- min_length = 3¶
- max_results = 100¶
- max_query_length = 100¶
- placeholder = ''¶
- no_results_text = 'No results found.'¶
- more_results_text = 'Showing the first %(count)s results. Narrow your search to see more.'¶
- min_length_text = 'Type at least %(count)s characters.'¶
- access_denied_text = "You don't have access to this search."¶
- login_required_text = 'Log in to use this search.'¶
- clean_query(query: str) str¶
Return the search text for the raw
qparameter.The default strips surrounding whitespace. Override this to keep whitespace that means something to
search, such as a leading space.
- search(query: str, request: HttpRequest) Sequence[Any] | QuerySet¶
Return a sliceable sequence of results matching
query.
- class izaya.ModelLookup¶
Bases:
LookupLookup over a Django model.
search_fieldsholds complete text field lookups, such asname__icontains, and a record matches if any of them do. Each one receives the search text as is, so other fields need asearchoverride.key_fieldnames the unique field whose value is submitted, and must match the form field’sto_field_name.rank_fieldsoptionally names text fields, such asname__unaccent, that put the closest matches first. A record ranks by its best match in any of them: the whole value, the start of the value, the start of a word, then everything else. Ties keep the queryset’s existing order, then fall back to the primary key.- key_field = 'pk'¶
- get_base_queryset() QuerySet¶
Return the records used for labels, such as with
select_relatedapplied.
- search(query: str, request: HttpRequest) QuerySet¶
Return a sliceable sequence of results matching
query.
- rank(queryset: QuerySet, query: str) QuerySet¶
Return
querysetwith the closest matches toqueryfirst.
- classmethod spawns_duplicates(fields: Iterable[str]) bool¶
Return whether any of
fieldscan match one record through several rows.
Widget¶
- class izaya.LookupWidget(lookup: type[Lookup], *, multiple: bool = False, classes: dict[str, str] | None = None, attrs: dict[str, Any] | None = None)¶
Form widget that picks one or more values from a registered lookup.
lookupis aLookupsubclass decorated with@register.multiple=Trueselects any number of values, for a multiple choice field.classesmaps the widget’s elements to CSS classes, replacing theIZAYA_CLASSESsetting’s value for each key it sets.
Settings¶
IZAYA_CLASSESA dict mapping the widget’s elements to CSS classes. A widget’s
classes=replaces its value for each key it sets. See Styling.IZAYA_LOGIN_REQUIREDWhen
True, every lookup denies anonymous searches unless it overrideshas_access. Defaults toFalse. See Private data.
System checks¶
izaya.E001A lookup’s
rank_fieldscrosses a to-many relation.izaya.W001IZAYA_LOGIN_REQUIREDis set, butAuthenticationMiddlewareisn’t inMIDDLEWARE.