diff options
| author | Shreya Bamne <shreya.bamne@gmail.com> | 2021-12-08 15:24:55 +0100 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2021-12-08 15:25:52 +0100 |
| commit | 8a4e5067605e608c3fcbb5ca11e0019eac8b40aa (patch) | |
| tree | 96d96bf001919d322c6f84f562f35b722a2c06fc /docs | |
| parent | 2b76f457494414f96d3848a5591909cbb48239e9 (diff) | |
Fixed #19721 -- Allowed admin filters to customize the list separator.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/contrib/admin/filters.txt | 19 | ||||
| -rw-r--r-- | docs/releases/4.1.txt | 4 |
2 files changed, 23 insertions, 0 deletions
diff --git a/docs/ref/contrib/admin/filters.txt b/docs/ref/contrib/admin/filters.txt index f78005936d..0dc119af3f 100644 --- a/docs/ref/contrib/admin/filters.txt +++ b/docs/ref/contrib/admin/filters.txt @@ -176,6 +176,25 @@ allows to store:: ('title', admin.EmptyFieldListFilter), ) +By defining a filter using the ``__in`` lookup, it is possible to filter for +any of a group of values. You need to override the ``expected_parameters`` +method, and the specify the ``lookup_kwargs`` attribute with the appropriate +field name. By default, multiple values in the query string will be separated +with commas, but this can be customized via the ``list_separator`` attribute. +The following example shows such a filter using the vertical-pipe character as +the separator:: + + class FilterWithCustomSeparator(admin.FieldListFilter): + # custom list separator that should be used to separate values. + list_separator = '|' + + def __init__(self, field, request, params, model, model_admin, field_path): + self.lookup_kwarg = '%s__in' % field_path + super().__init__(field, request, params, model, model_admin, field_path) + + def expected_parameters(self): + return [self.lookup_kwarg] + .. note:: The :class:`~django.contrib.contenttypes.fields.GenericForeignKey` field is diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt index 543c9caf6e..c55e638695 100644 --- a/docs/releases/4.1.txt +++ b/docs/releases/4.1.txt @@ -54,6 +54,10 @@ Minor features * The admin :ref:`dark mode CSS variables <admin-theming>` are now applied in a separate stylesheet and template block. +* :ref:`modeladmin-list-filters` providing custom ``FieldListFilter`` + subclasses can now control the query string value separator when filtering + for multiple values using the ``__in`` lookup. + :mod:`django.contrib.admindocs` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
