Skip to content

Commit 79fd3f9

Browse files
authored
Allow text choices being directly assigned as choices. (typeddjango#261)
Allow CharField(choices=...) to be a TextChoices class. Changed in Django 5.0, see note here: https://docs.djangoproject.com/en/5.0/ref/models/fields/#s-enumeration-types
1 parent 1ede371 commit 79fd3f9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

django-stubs/db/models/fields/__init__.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from typing_extensions import Literal, Self
88

99
from django.core.checks import CheckMessage
1010
from django.core.exceptions import FieldDoesNotExist as FieldDoesNotExist
11-
from django.db.models import Model
11+
from django.db.models import Model, TextChoices
1212
from django.db.models.expressions import Col, Combinable
1313
from django.db.models.query_utils import RegisterLookupMixin
1414
from django.forms import Widget
@@ -679,7 +679,8 @@ class CharField(Generic[_C], Field[_C | Combinable, _C]):
679679
unique_for_date: str | None = ...,
680680
unique_for_month: str | None = ...,
681681
unique_for_year: str | None = ...,
682-
choices: Iterable[tuple[_C, str] | tuple[str, Iterable[tuple[_C, str]]]] = ...,
682+
choices: Iterable[tuple[_C, str] | tuple[str, Iterable[tuple[_C, str]]]]
683+
| type[TextChoices] = ...,
683684
help_text: str = ...,
684685
db_column: str | None = ...,
685686
db_comment: str | None = ...,
@@ -706,7 +707,8 @@ class CharField(Generic[_C], Field[_C | Combinable, _C]):
706707
unique_for_date: str | None = ...,
707708
unique_for_month: str | None = ...,
708709
unique_for_year: str | None = ...,
709-
choices: Iterable[tuple[_C, str] | tuple[str, Iterable[tuple[_C, str]]]] = ...,
710+
choices: Iterable[tuple[_C, str] | tuple[str, Iterable[tuple[_C, str]]]]
711+
| type[TextChoices] = ...,
710712
help_text: str = ...,
711713
db_column: str | None = ...,
712714
db_comment: str | None = ...,

0 commit comments

Comments
 (0)