django_choices_js API

apps

class django_choices_js.apps.DjangoChoicesJsConfig(app_name, app_module)[source]

Bases: AppConfig

name = 'django_choices_js'

forms

class django_choices_js.forms.ChoicesJsMixin(choices_opts: dict = None, *args, **kwargs)[source]

Bases: object

The base class of all Choices.js widgets.

This adds the media property that includes all necessary css and js tags for Choices.js.

Parameters:

choices_opts (dict) – Options that are passed directly to the Choices.js constructor.

build_attrs(base_attrs, extra_attrs=None)[source]
property media
class django_choices_js.forms.ChoicesJsTextInput(choices_opts: dict = None, *args, **kwargs)[source]

Bases: ChoicesJsMixin, TextInput

A widget for text input that allows multiple entries separated by a delimiter (default ',').

Example:

text = django.forms.CharField(widget=django_choices_js.ChoicesJsTextInput, choices_opts={'maxItemCount': 3})
Parameters:

choices_opts (dict) – Options that are passed directly to the Choices.js constructor.

property media
class django_choices_js.forms.ChoicesJsSelect(choices_opts: dict = None, *args, **kwargs)[source]

Bases: ChoicesJsMixin, Select

Parameters:

choices_opts (dict) – Options that are passed directly to the Choices.js constructor.

property media
class django_choices_js.forms.ChoicesJsSelectMultiple(choices_opts: dict = None, *args, **kwargs)[source]

Bases: ChoicesJsMixin, SelectMultiple

Parameters:

choices_opts (dict) – Options that are passed directly to the Choices.js constructor.

property media
class django_choices_js.forms.ChoicesJsModelMixin(choices_opts=None, autocomplete_name=None, *args, **kwargs)[source]

Bases: ChoicesJsMixin

Parameters:

choices_opts (dict) – Options that are passed directly to the Choices.js constructor.

build_attrs(base_attrs, extra_attrs=None)[source]
optgroups(name, value, attrs=None)[source]
class django_choices_js.forms.ChoicesJSModelSelect(choices_opts=None, autocomplete_name=None, *args, **kwargs)[source]

Bases: ChoicesJsModelMixin, Select

Parameters:

choices_opts (dict) – Options that are passed directly to the Choices.js constructor.

property media
class django_choices_js.forms.ChoicesJSModelSelectMultiple(choices_opts=None, autocomplete_name=None, *args, **kwargs)[source]

Bases: ChoicesJsModelMixin, SelectMultiple

Parameters:

choices_opts (dict) – Options that are passed directly to the Choices.js constructor.

property media
exception django_choices_js.forms.InvalidAutocomplete(message)[source]

Bases: Exception

models

class django_choices_js.models.ChoicesAutocompletePathConfig(path: str, fields: dict[str, list[Literal['exact', 'iexact', 'contains', 'icontains', 'startswith', 'istartswith', 'endswith', 'iendswith', 'regex', 'iregex']]], permission: str | None)[source]

Bases: object

path: str
fields: dict[str, list[Literal['exact', 'iexact', 'contains', 'icontains', 'startswith', 'istartswith', 'endswith', 'iendswith', 'regex', 'iregex']]]
permission: str | None
django_choices_js.models.autocomplete_path_for_model(model: Model, name: str | None = None)[source]
django_choices_js.models.autocomplete_model(fields: list[str] | dict[str, list[Literal['exact', 'iexact', 'contains', 'icontains', 'startswith', 'istartswith', 'endswith', 'iendswith', 'regex', 'iregex']]], name: str | None = None, permission: str | None = None)[source]

Decorator that registers an autocompletion endpoint for a given model.

Parameters:
  • fields – The fields that should be searched for autocompletion. Can be either a list of field names or a dict with field names as keys and a list of lookup functions as values. If a list is passed, icontains will be used as the default lookup function.

  • name – Optional identifier for the autocomplete path. If None, it will become the default path for the model.

  • permission – Required django permission to use the autocompletion endpoint. If None, it will be accessible to everyone.

Examples:

@autocomplete_model(fields=['name'])
@autocomplete_model(fields={'name': ['istartswith', 'iendswith']}, name='prefix_or_suffix')
exception django_choices_js.models.AutocompletePathAlreadyRegistered(message)[source]

Bases: Exception

urls

views

django_choices_js.views.autocomplete(req: WSGIRequest, path: str)[source]