Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions django-stubs/contrib/admin/filters.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class ListFilter:
title: _StrOrPromise | None
template: str
request: HttpRequest
used_parameters: dict[str, bool | datetime | str]
used_parameters: dict[str, list[str] | list[bool]]
def __init__(
self, request: HttpRequest, params: dict[str, str], model: type[Model], model_admin: ModelAdmin
self, request: HttpRequest, params: dict[str, list[str]], model: type[Model], model_admin: ModelAdmin
) -> None: ...
def has_output(self) -> bool: ...
def choices(self, changelist: ChangeList) -> Iterator[_ListFilterChoices]: ...
Expand All @@ -39,6 +39,8 @@ class FacetsMixin:
def get_facet_queryset(self, changelist: ChangeList) -> dict[str, int]: ...

class SimpleListFilter(FacetsMixin, ListFilter):
# SimpleListFilter stores scalar str (value[-1]) instead of list, breaking the base class contract
used_parameters: dict[str, str] # type: ignore[assignment]
parameter_name: str | None
lookup_choices: list[tuple[str, _StrOrPromise]]
def value(self) -> str | None: ...
Expand All @@ -52,7 +54,7 @@ class FieldListFilter(FacetsMixin, ListFilter):
self,
field: Field,
request: HttpRequest,
params: dict[str, str],
params: dict[str, list[str]],
model: type[Model],
model_admin: ModelAdmin,
field_path: str,
Expand All @@ -66,7 +68,7 @@ class FieldListFilter(FacetsMixin, ListFilter):
cls,
field: Field,
request: HttpRequest,
params: dict[str, str],
params: dict[str, list[str]],
model: type[Model],
model_admin: ModelAdmin,
field_path: str,
Expand Down
12 changes: 8 additions & 4 deletions django-stubs/contrib/admin/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
from collections import defaultdict
from collections.abc import Callable, Iterable, Sequence
from typing import Any, Literal, TypeVar, overload, type_check_only
Expand Down Expand Up @@ -28,9 +27,14 @@ class FieldIsAForeignKeyColumnName(Exception): ...

def lookup_spawns_duplicates(opts: Options, lookup_path: str) -> bool: ...
def get_last_value_from_parameters(parameters: dict[str, list[str] | str], key: str) -> str | None: ...
def prepare_lookup_value(
key: str, value: list[bool | datetime.datetime | str] | datetime.datetime | str, separator: str = ...
) -> list[bool | datetime.datetime | str] | bool | datetime.datetime | str: ...

# The implementation recurses on list inputs, but the contract is list[str] | str
# input only (lookup parameters are supposed to be flat string lists) — do not type the
# return as a recursive/deeply-nested type.
@overload
def prepare_lookup_value(key: str, value: list[str], separator: str = ...) -> list[str] | list[bool]: ...
@overload
def prepare_lookup_value(key: str, value: str, separator: str = ...) -> str | bool | list[str]: ...
def build_q_object_from_lookup_parameters(parameters: dict[str, list[str]]) -> Q: ...
def quote(s: int | str | UUID) -> str: ...
def unquote(s: str) -> str: ...
Expand Down
Loading