@@ -8,6 +8,7 @@ from django.db.models.base import Model
88from django .db .models .fields import _AllLimitChoicesTo , _LimitChoicesTo
99from django .db .models .manager import Manager
1010from django .db .models .query import QuerySet
11+ from django .db .models .utils import AltersData
1112from django .forms .fields import ChoiceField , Field , _ClassLevelWidgetT
1213from django .forms .forms import BaseForm , DeclarativeFieldsMetaclass
1314from django .forms .formsets import BaseFormSet
@@ -17,6 +18,7 @@ from django.forms.widgets import Widget
1718from django .utils .choices import BaseChoiceIterator , CallableChoiceIterator , _ChoicesCallable , _ChoicesInput
1819from django .utils .datastructures import _PropertyDescriptor
1920from django .utils .functional import _StrOrPromise
21+ from typing_extensions import Self
2022
2123ALL_FIELDS : Literal ["__all__" ]
2224
@@ -67,7 +69,7 @@ class ModelFormOptions(Generic[_M]):
6769
6870class ModelFormMetaclass (DeclarativeFieldsMetaclass ): ...
6971
70- class BaseModelForm (BaseForm , Generic [_M ]):
72+ class BaseModelForm (BaseForm , AltersData , Generic [_M ]):
7173 instance : _M
7274 _meta : ModelFormOptions [_M ]
7375 def __init__ (
@@ -109,7 +111,7 @@ def modelform_factory(
109111
110112_ModelFormT = TypeVar ("_ModelFormT" , bound = ModelForm )
111113
112- class BaseModelFormSet (BaseFormSet [_ModelFormT ], Generic [_M , _ModelFormT ]):
114+ class BaseModelFormSet (BaseFormSet [_ModelFormT ], AltersData , Generic [_M , _ModelFormT ]):
113115 model : type [_M ]
114116 edit_only : bool
115117 unique_fields : Collection [str ]
@@ -194,6 +196,14 @@ class BaseInlineFormSet(BaseModelFormSet[_M, _ModelFormT], Generic[_M, _ParentM,
194196 def add_fields (self , form : _ModelFormT , index : int | None ) -> None : ...
195197 def get_unique_error_message (self , unique_check : Sequence [str ]) -> str : ...
196198
199+ @overload
200+ def _get_foreign_key (
201+ parent_model : type [Model ], model : type [Model ], fk_name : str | None = None , can_fail : Literal [False ] = ...
202+ ) -> ForeignKey : ...
203+ @overload
204+ def _get_foreign_key (
205+ parent_model : type [Model ], model : type [Model ], fk_name : str | None = None , can_fail : Literal [True ] = ...
206+ ) -> ForeignKey | None : ...
197207def inlineformset_factory (
198208 parent_model : type [_ParentM ],
199209 model : type [_M ],
@@ -282,6 +292,7 @@ class ModelChoiceField(ChoiceField, Generic[_M]):
282292 ) -> None : ...
283293 def validate_no_null_characters (self , value : Any ) -> None : ...
284294 def get_limit_choices_to (self ) -> _LimitChoicesTo : ...
295+ def __deepcopy__ (self , memo : dict [int , Any ]) -> Self : ...
285296 def label_from_instance (self , obj : _M ) -> str : ...
286297 choices : _PropertyDescriptor [
287298 _ChoicesInput | _ChoicesCallable | CallableChoiceIterator ,
@@ -307,14 +318,6 @@ class ModelMultipleChoiceField(ModelChoiceField[_M]):
307318 def has_changed (self , initial : Collection [Any ] | None , data : Collection [Any ] | None ) -> bool : ... # type: ignore[override]
308319
309320def modelform_defines_fields (form_class : type [ModelForm ]) -> bool : ...
310- @overload
311- def _get_foreign_key (
312- parent_model : type [Model ], model : type [Model ], fk_name : str | None = None , can_fail : Literal [True ] = True
313- ) -> ForeignKey | None : ...
314- @overload
315- def _get_foreign_key (
316- parent_model : type [Model ], model : type [Model ], fk_name : str | None = None , can_fail : Literal [False ] = False
317- ) -> ForeignKey : ...
318321
319322__all__ = (
320323 "ALL_FIELDS" ,
0 commit comments