Skip to content

Commit

Permalink
Allow None return form model Field.formfield() (#2363)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz authored Sep 9, 2024
1 parent 31f5ccb commit 0efa35d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions django-stubs/contrib/admin/options.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ class BaseModelAdmin(Generic[_ModelT]):
admin_site: AdminSite
def __init__(self) -> None: ...
def check(self, **kwargs: Any) -> list[CheckMessage]: ...
def formfield_for_dbfield(self, db_field: Field, request: HttpRequest, **kwargs: Any) -> FormField: ...
def formfield_for_choice_field(self, db_field: Field, request: HttpRequest, **kwargs: Any) -> TypedChoiceField: ...
def formfield_for_dbfield(self, db_field: Field, request: HttpRequest, **kwargs: Any) -> FormField | None: ...
def formfield_for_choice_field(
self, db_field: Field, request: HttpRequest, **kwargs: Any
) -> TypedChoiceField | None: ...
def get_field_queryset(self, db: str | None, db_field: RelatedField, request: HttpRequest) -> QuerySet | None: ...
def formfield_for_foreignkey(
self, db_field: ForeignKey, request: HttpRequest, **kwargs: Any
) -> ModelChoiceField: ...
) -> ModelChoiceField | None: ...
def formfield_for_manytomany(
self, db_field: ManyToManyField, request: HttpRequest, **kwargs: Any
) -> ModelMultipleChoiceField | None: ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/fields/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
form_class: type[forms.Field] | None = None,
choices_form_class: type[forms.ChoiceField] | None = None,
**kwargs: Any,
) -> forms.Field: ...
) -> forms.Field | None: ...
def save_form_data(self, instance: Model, data: Any) -> None: ...
def contribute_to_class(self, cls: type[Model], name: str, private_only: bool = False) -> None: ...
def to_python(self, value: Any) -> Any: ...
Expand Down

0 comments on commit 0efa35d

Please sign in to comment.