diff --git a/django-stubs/db/models/__init__.pyi b/django-stubs/db/models/__init__.pyi index d23fb5bf7..483225654 100644 --- a/django-stubs/db/models/__init__.pyi +++ b/django-stubs/db/models/__init__.pyi @@ -74,6 +74,7 @@ from .fields import URLField as URLField from .fields import UUIDField as UUIDField from .fields.files import FileField as FileField from .fields.files import ImageField as ImageField +from .fields.generated import GeneratedField as GeneratedField from .fields.json import JSONField as JSONField from .fields.proxy import OrderWrt as OrderWrt from .fields.related import ForeignKey as ForeignKey diff --git a/django-stubs/db/models/fields/generated.pyi b/django-stubs/db/models/fields/generated.pyi new file mode 100644 index 000000000..2a137c4b4 --- /dev/null +++ b/django-stubs/db/models/fields/generated.pyi @@ -0,0 +1,47 @@ +from typing import Any, Iterable, Literal + +from django.core.validators import _ValidatorCallable +from django.db import models +from django.db.backends.base.base import BaseDatabaseWrapper +from django.db.models.expressions import Expression +from django.db.models.fields import _ErrorMessagesMapping, _FieldChoices +from django.db.models.sql import Query +from django.utils.datastructures import DictWrapper +from django.utils.functional import _StrOrPromise + +class GeneratedField(models.Field): + generated: Literal[True] + db_returning: Literal[True] + _query: Query | None + output_field: models.Field | None + + def __init__( + self, + *, + expression: Expression, + output_field: models.Field, + db_persist: bool | None = ..., + verbose_name: _StrOrPromise | None = ..., + name: str | None = ..., + primary_key: bool = ..., + unique: bool = ..., + blank: bool = ..., + null: bool = ..., + default: Any = ..., + editable: bool = ..., + auto_created: bool = ..., + serialize: bool = ..., + unique_for_date: str | None = ..., + unique_for_month: str | None = ..., + unique_for_year: str | None = ..., + choices: _FieldChoices | None = ..., + help_text: _StrOrPromise = ..., + db_column: str | None = ..., + db_comment: str | None = ..., + db_tablespace: str | None = ..., + validators: Iterable[_ValidatorCallable] = ..., + error_messages: _ErrorMessagesMapping | None = ..., + **kwargs: Any, + ) -> None: ... + def generated_sql(self, connection: BaseDatabaseWrapper) -> tuple[str, Any]: ... + def db_type_parameters(self, connection: BaseDatabaseWrapper) -> DictWrapper: ... diff --git a/scripts/stubtest/allowlist.txt b/scripts/stubtest/allowlist.txt index 0e28c9fa6..ca96d4868 100644 --- a/scripts/stubtest/allowlist.txt +++ b/scripts/stubtest/allowlist.txt @@ -182,6 +182,7 @@ django.contrib.gis.db.models.ForeignObjectRel.name django.contrib.gis.db.models.ForeignObjectRel.one_to_many django.contrib.gis.db.models.ForeignObjectRel.one_to_one django.contrib.gis.db.models.ForeignObjectRel.related_model +django.contrib.gis.db.models.GeneratedField.cached_col django.contrib.gis.db.models.IntegerField.validators django.contrib.gis.db.models.Lookup.contains_aggregate django.contrib.gis.db.models.Lookup.contains_over_clause @@ -300,6 +301,7 @@ django.db.models.ForeignObjectRel.name django.db.models.ForeignObjectRel.one_to_many django.db.models.ForeignObjectRel.one_to_one django.db.models.ForeignObjectRel.related_model +django.db.models.GeneratedField.cached_col django.db.models.IntegerField.validators django.db.models.Lookup.contains_aggregate django.db.models.Lookup.contains_over_clause @@ -313,6 +315,7 @@ django.db.models.fields.DecimalField.validators django.db.models.fields.Field.cached_col django.db.models.fields.Field.validators django.db.models.fields.IntegerField.validators +django.db.models.fields.generated.GeneratedField.cached_col django.db.models.fields.related.ForeignObject.foreign_related_fields django.db.models.fields.related.ForeignObject.local_related_fields django.db.models.fields.related.ForeignObject.related_fields diff --git a/scripts/stubtest/allowlist_todo_django50.txt b/scripts/stubtest/allowlist_todo_django50.txt index fa9f901a1..3d71345a8 100644 --- a/scripts/stubtest/allowlist_todo_django50.txt +++ b/scripts/stubtest/allowlist_todo_django50.txt @@ -70,7 +70,6 @@ django.contrib.gis.db.models.ForeignObject.get_joining_fields django.contrib.gis.db.models.ForeignObject.get_reverse_joining_fields django.contrib.gis.db.models.ForeignObjectRel.get_joining_fields django.contrib.gis.db.models.Func.allowed_default -django.contrib.gis.db.models.GeneratedField django.contrib.gis.db.models.Lookup.allowed_default django.contrib.gis.db.models.Prefetch.get_current_querysets django.contrib.gis.db.models.Q.identity @@ -181,7 +180,6 @@ django.db.models.ForeignObject.get_joining_fields django.db.models.ForeignObject.get_reverse_joining_fields django.db.models.ForeignObjectRel.get_joining_fields django.db.models.Func.allowed_default -django.db.models.GeneratedField django.db.models.Lookup.allowed_default django.db.models.Prefetch.get_current_querysets django.db.models.Q.identity @@ -206,7 +204,6 @@ django.db.models.expressions.When.allowed_default django.db.models.fields.Field.__init__ django.db.models.fields.Field._get_flatchoices django.db.models.fields.Field.generated -django.db.models.fields.generated django.db.models.fields.related.ForeignKey.cast_db_type django.db.models.fields.related.ForeignObject.get_joining_fields django.db.models.fields.related.ForeignObject.get_reverse_joining_fields