This class manages the logic for displaying and interacting with a list of model instances in an administrative interface. It handles the processing of query string parameters to perform filtering, searching, ordering, and pagination on a base queryset. Additionally, it coordinates with model administration settings to determine display fields, link behavior, and result counts.
Attributes
| Attribute | Type | Description |
|---|
| search_form_class | class = ChangeListSearchForm | The form class used to instantiate the search form for processing query parameters. Defaults to ChangeListSearchForm. |
Constructor
Signature
def ChangeList(
request: [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest),
model: [Model](../../../../db/models/base/model.md?sid=django_db_models_base_model),
list_display: list,
list_display_links: list,
list_filter: list,
date_hierarchy: str,
search_fields: list,
list_select_related: bool or list,
list_per_page: int,
list_max_show_all: int,
list_editable: list,
model_admin: [ModelAdmin](../../options/modeladmin.md?sid=django_contrib_admin_options_modeladmin),
sortable_by: list,
search_help_text: str
) - > null
Parameters
| Name | Type | Description |
|---|
| request | [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The current HTTP request object. |
| model | [Model](../../../../db/models/base/model.md?sid=django_db_models_base_model) | The Django model class being displayed. |
| list_display | list | Fields to be displayed in the change list. |
| list_display_links | list | Fields that should link to the change view. |
| list_filter | list | Fields or classes to use for filtering the list. |
| date_hierarchy | str | The name of a DateField or DateTimeField to use for date-based drill-down. |
| search_fields | list | Fields to be used in the search functionality. |
| list_select_related | bool or list | Specifies whether to use select_related() for the queryset. |
| list_per_page | int | Number of items to display per page. |
| list_max_show_all | int | Maximum number of items allowed on a 'Show all' page. |
| list_editable | list | Fields that are editable directly on the change list page. |
| model_admin | [ModelAdmin](../../options/modeladmin.md?sid=django_contrib_admin_options_modeladmin) | The ModelAdmin instance associated with the model. |
| sortable_by | list | Fields that the user is allowed to sort by. |
| search_help_text | str | Help text to display for the search bar. |
Methods
get_filters_params()
@classmethod
def get_filters_params(
params: dict = null
) - > dict
Return all params except IGNORED_PARAMS.
Parameters
| Name | Type | Description |
|---|
| params | dict = null | The raw query parameters to filter; defaults to the instance's filter_params if not provided. |
Returns
| Type | Description |
|---|
dict | A dictionary of query string parameters filtered to remove globally ignored keys. |
get_filters()
@classmethod
def get_filters(
request: [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest)
) - > tuple
Identifies and initializes the filter specifications based on the request and current lookup parameters.
Parameters
| Name | Type | Description |
|---|
| request | [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The current request object used to validate lookups and initialize filter classes. |
Returns
| Type | Description |
|---|
tuple | A tuple containing filter specs, a boolean for filter existence, remaining lookup params, and flags for duplicates and active filters. |
get_query_string()
@classmethod
def get_query_string(
new_params: dict = null,
remove: list = null
) - > string
Constructs a URL-encoded query string by merging new parameters and removing specified keys from the current filter state.
Parameters
| Name | Type | Description |
|---|
| new_params | dict = null | A dictionary of parameters to add or update in the query string. |
| remove | list = null | A list of parameter keys or prefixes to exclude from the resulting query string. |
Returns
| Type | Description |
|---|
string | A URL-encoded query string starting with a question mark. |
get_results()
@classmethod
def get_results(
request: [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest)
) - > null
Executes the queryset and populates the instance with pagination data and the final list of objects for display.
Parameters
| Name | Type | Description |
|---|
| request | [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The current request object used to retrieve the paginator and current page. |
Returns
get_ordering_field()
@classmethod
def get_ordering_field(
field_name: string
) - > string
Return the proper model field name corresponding to the given field_name to use for ordering.
Parameters
| Name | Type | Description |
|---|
| field_name | string | The name of the field, method, or callable to resolve into an orderable model field. |
Returns
| Type | Description |
|---|
string | The actual model field name or admin_order_field attribute, or None if no match is found. |
get_ordering()
@classmethod
def get_ordering(
request: [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest),
queryset: [QuerySet](../../../../db/models/query/queryset.md?sid=django_db_models_query_queryset)
) - > list
Return the list of ordering fields for the change list.
Parameters
| Name | Type | Description |
|---|
| request | [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The current request object used to fetch ordering preferences from the ModelAdmin. |
| queryset | [QuerySet](../../../../db/models/query/queryset.md?sid=django_db_models_query_queryset) | The current queryset used to check existing ordering and ensure total ordering. |
Returns
| Type | Description |
|---|
list | A list of ordering strings or expressions, guaranteed to provide a deterministic order. |
get_ordering_field_columns()
@classmethod
def get_ordering_field_columns() - > dict
Return a dictionary of ordering field column numbers and asc/desc.
Returns
| Type | Description |
|---|
dict | A mapping of integer column indices to their sort direction ('asc' or 'desc'). |
get_queryset()
@classmethod
def get_queryset(
request: [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest),
exclude_parameters: list = null
) - > [QuerySet](../../../../db/models/query/queryset.md?sid=django_db_models_query_queryset)
Builds the final filtered and ordered queryset by applying filters, search terms, and generic lookup parameters.
Parameters
| Name | Type | Description |
|---|
| request | [HttpRequest](../../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The current request object used to process filters and search. |
| exclude_parameters | list = null | A list of parameters to skip when applying filter specifications. |
Returns
| Type | Description |
|---|
[QuerySet](../../../../db/models/query/queryset.md?sid=django_db_models_query_queryset) | The processed queryset ready for pagination and display. |
@classmethod
def apply_select_related(
qs: [QuerySet](../../../../db/models/query/queryset.md?sid=django_db_models_query_queryset)
) - > [QuerySet](../../../../db/models/query/queryset.md?sid=django_db_models_query_queryset)
Applies select_related optimization to the queryset based on the list_select_related configuration.
Parameters
| Name | Type | Description |
|---|
| qs | [QuerySet](../../../../db/models/query/queryset.md?sid=django_db_models_query_queryset) | The queryset to which select_related should be applied. |
Returns
| Type | Description |
|---|
[QuerySet](../../../../db/models/query/queryset.md?sid=django_db_models_query_queryset) | The optimized queryset with related object fetching configured. |
@classmethod
def get_select_related_fields() - > list
Identifies foreign key fields in list_display that should be included in a select_related call.
Returns
| Type | Description |
|---|
list | A list of field names representing ManyToOne relations suitable for select_related. |
url_for_result()
@classmethod
def url_for_result(
result: object
) - > string
Generates the admin change URL for a specific model instance in the result list.
Parameters
| Name | Type | Description |
|---|
| result | object | The model instance for which the URL is being generated. |
Returns
| Type | Description |
|---|
string | The absolute URL path to the change form for the given result object. |