AutocompleteJsonView
Handle AutocompleteWidget's AJAX requests for data.
Attributes
| Attribute | Type | Description |
|---|---|---|
| paginate_by | int = 20 | The maximum number of search results to return per page in the autocomplete response. |
| admin_site | django.contrib.admin.sites.AdminSite = null | The AdminSite instance used to retrieve the ModelAdmin for the target model and validate permissions. |
Methods
get()
@classmethod
def get(
request: [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest)
) - > [JsonResponse](../../../../http/response/jsonresponse.md?sid=django_http_response_jsonresponse)
Return a JsonResponse with search results as defined in serialize_result(), by default: { results: [{id: "123" text: "foo"}], pagination: {more: true} }
Parameters
| Name | Type | Description |
|---|---|---|
| request | [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The incoming HTTP request object containing search parameters. |
Returns
| Type | Description |
|---|---|
[JsonResponse](../../../../http/response/jsonresponse.md?sid=django_http_response_jsonresponse) | A JSON response containing the serialized search results and a boolean flag indicating if more pages exist. |
serialize_result()
@classmethod
def serialize_result(
obj: [Model](../../../../db/models/base/model.md?sid=django_db_models_base_model),
to_field_name: string
) - > dict
Convert the provided model object to a dictionary that is added to the results list.
Parameters
| Name | Type | Description |
|---|---|---|
| obj | [Model](../../../../db/models/base/model.md?sid=django_db_models_base_model) | The Django model instance to be serialized into a result dictionary. |
| to_field_name | string | The name of the model field to use as the unique identifier in the result. |
Returns
| Type | Description |
|---|---|
dict | A dictionary containing the 'id' and 'text' representation of the model instance. |
get_paginator()
@classmethod
def get_paginator() - > [Paginator](../../../../core/paginator/paginator.md?sid=django_core_paginator_paginator)
Use the ModelAdmin's paginator.
Returns
| Type | Description |
|---|---|
[Paginator](../../../../core/paginator/paginator.md?sid=django_core_paginator_paginator) | The paginator instance associated with the target ModelAdmin. |
get_queryset()
@classmethod
def get_queryset() - > [QuerySet](../../../../db/models/query/queryset.md?sid=django_db_models_query_queryset)
Return queryset based on ModelAdmin.get_search_results().
Returns
| Type | Description |
|---|---|
[QuerySet](../../../../db/models/query/queryset.md?sid=django_db_models_query_queryset) | A filtered and potentially distinct QuerySet of model instances matching the search term. |
process_request()
@classmethod
def process_request(
request: [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest)
) - > tuple
Validate request integrity, extract and return request parameters.
Parameters
| Name | Type | Description |
|---|---|---|
| request | [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The request object containing the app_label, model_name, and field_name required for validation. |
Returns
| Type | Description |
|---|---|
tuple | A tuple containing the search term, the ModelAdmin instance, the source field, and the target field name. |
has_perm()
@classmethod
def has_perm(
request: [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest),
obj: [Model](../../../../db/models/base/model.md?sid=django_db_models_base_model) = null
) - > boolean
Check if user has permission to access the related model.
Parameters
| Name | Type | Description |
|---|---|---|
| request | [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The current request object used to verify user authentication and permissions. |
| obj | [Model](../../../../db/models/base/model.md?sid=django_db_models_base_model) = null | An optional model instance to check permissions against. |
Returns
| Type | Description |
|---|---|
boolean | True if the user has view permissions for the related model, otherwise False. |