forked from typeddjango/djangorestframework-stubs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelations.pyi
194 lines (180 loc) · 6.95 KB
/
relations.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
from collections.abc import Callable, Iterable, Mapping, Sequence
from typing import Any, Generic, TypeVar
from django.db.models import Manager, Model, QuerySet
from django_stubs_ext import StrOrPromise
from rest_framework.fields import Field, Option
from rest_framework.request import Request
from rest_framework.validators import Validator
from typing_extensions import Self
def method_overridden(method_name: str, klass: type, instance: Model) -> bool: ...
class ObjectValueError(ValueError): ...
class ObjectTypeError(TypeError): ...
class Hyperlink(str):
def __new__(cls, url: str, obj: Any) -> Self: ...
def __getnewargs__(self) -> tuple[str, str]: ... # type: ignore[override]
@property
def name(self) -> str: ...
is_hyperlink: bool
obj: Any
class PKOnlyObject:
pk: Any
def __init__(self, pk: Any) -> None: ...
MANY_RELATION_KWARGS: Sequence[str]
_MT = TypeVar("_MT", bound=Model)
_DT = TypeVar("_DT") # Data Type
_PT = TypeVar("_PT") # Primitive Type
class RelatedField(Generic[_MT, _DT, _PT], Field[_MT, _DT, _PT, Any]):
queryset: QuerySet[_MT] | Manager[_MT] | None
html_cutoff: int | None
html_cutoff_text: str | None
def __init__(
self,
*,
many: bool = ...,
allow_empty: bool = ...,
queryset: QuerySet[_MT] | Manager[_MT] | None = ...,
html_cutoff: int | None = ...,
html_cutoff_text: str = ...,
read_only: bool = ...,
write_only: bool = ...,
required: bool | None = None,
default: Any = ...,
initial: Any = ...,
source: str | None = None,
label: StrOrPromise | None = ...,
help_text: StrOrPromise | None = None,
allow_null: bool = ...,
validators: Sequence[Validator[_MT]] | None = ...,
error_messages: dict[str, StrOrPromise] | None = ...,
style: dict[str, str] | None = ...,
) -> None: ...
# mypy doesn't accept the typing below, although its accurate to what this class is doing, hence the ignore
def __new__(cls, *args: Any, **kwargs: Any) -> RelatedField[_MT, _DT, _PT] | ManyRelatedField: ... # type: ignore
@classmethod
def many_init(cls, *args: Any, **kwargs: Any) -> ManyRelatedField: ...
def get_queryset(self) -> QuerySet[_MT]: ...
def use_pk_only_optimization(self) -> bool: ...
def get_choices(self, cutoff: int | None = ...) -> dict: ...
@property
def choices(self) -> dict: ...
@property
def grouped_choices(self) -> dict: ...
def iter_options(self) -> Iterable[Option]: ...
def get_attribute(self, instance: _MT) -> _PT | None: ...
def display_value(self, instance: _MT) -> str: ...
class StringRelatedField(RelatedField[_MT, _MT, str]): ...
class PrimaryKeyRelatedField(RelatedField[_MT, _MT, Any]):
pk_field: str | None
def __init__(
self,
*,
many: bool = ...,
allow_empty: bool = ...,
queryset: QuerySet[_MT] | Manager[_MT] | None = ...,
html_cutoff: int | None = ...,
html_cutoff_text: str = ...,
read_only: bool = ...,
write_only: bool = ...,
required: bool | None = None,
default: Any = ...,
initial: Any = ...,
source: str | None = None,
label: StrOrPromise | None = ...,
help_text: StrOrPromise | None = None,
allow_null: bool = ...,
validators: Sequence[Validator[_MT]] | None = ...,
error_messages: dict[str, StrOrPromise] | None = ...,
style: dict[str, str] | None = ...,
pk_field: str | Field | None = ...,
) -> None: ...
class HyperlinkedRelatedField(RelatedField[_MT, str, Hyperlink]):
reverse: Callable
lookup_field: str
lookup_url_kwarg: str
format: str | None
view_name: str | None
def __init__(
self,
view_name: str | None = ...,
*,
many: bool = ...,
allow_empty: bool = ...,
queryset: QuerySet[_MT] | Manager[_MT] | None = ...,
html_cutoff: int | None = ...,
html_cutoff_text: str = ...,
read_only: bool = ...,
write_only: bool = ...,
required: bool | None = None,
default: Any = ...,
initial: Any = ...,
source: str | None = None,
label: StrOrPromise | None = ...,
help_text: StrOrPromise | None = None,
allow_null: bool = ...,
validators: Sequence[Validator[_MT]] | None = ...,
error_messages: dict[str, StrOrPromise] | None = ...,
style: dict[str, str] | None = ...,
lookup_field: str | None = ...,
lookup_url_kwarg: str | None = ...,
format: str | None = ...,
) -> None: ...
def get_object(self, view_name: str, *view_args: Any, **view_kwargs: Any) -> _MT: ...
def get_url(self, obj: Model, view_name: str, request: Request, format: str | None) -> str | None: ...
class HyperlinkedIdentityField(HyperlinkedRelatedField): ...
class SlugRelatedField(RelatedField[_MT, str, str]):
slug_field: str | None
def __init__(
self,
slug_field: str,
*,
many: bool = ...,
allow_empty: bool = ...,
queryset: QuerySet[_MT] | Manager[_MT] | None = ...,
html_cutoff: int | None = ...,
html_cutoff_text: str = ...,
read_only: bool = ...,
write_only: bool = ...,
required: bool | None = None,
default: _DT = ...,
initial: _MT | Callable[[Any], _MT] = ...,
source: str | None = None,
label: StrOrPromise | None = ...,
help_text: StrOrPromise | None = None,
allow_null: bool = ...,
validators: Sequence[Validator[_MT]] | None = ...,
error_messages: dict[str, StrOrPromise] | None = ...,
style: dict[str, str] | None = ...,
) -> None: ...
def to_internal_value(self, data: Any) -> _MT: ...
def to_representation(self, value: _MT) -> str: ...
class ManyRelatedField(Field[Sequence[Any], Sequence[Any], list[Any], Any]):
default_empty_html: list[object]
html_cutoff: int | None
html_cutoff_text: str | None
child_relation: RelatedField
allow_empty: bool
def __init__(
self,
child_relation: RelatedField = ...,
*,
read_only: bool = ...,
write_only: bool = ...,
required: bool | None = None,
default: Sequence[Any] = ...,
initial: Sequence[Any] | Callable[[Any], Sequence[Any]] = ...,
source: str | None = None,
label: StrOrPromise | None = ...,
help_text: str | None = ...,
style: dict[str, str] | None = ...,
error_messages: dict[str, StrOrPromise] | None = ...,
validators: Sequence[Validator[Sequence[Any]]] | None = ...,
allow_null: bool = ...,
allow_empty: bool = ...,
) -> None: ...
def get_value(self, dictionary: Mapping[Any, Any]) -> list[Any]: ...
def get_choices(self, cutoff: int | None = ...) -> dict: ...
@property
def choices(self) -> dict: ...
@property
def grouped_choices(self) -> dict: ...
def iter_options(self) -> Iterable[Option]: ...