Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0] Add django.db.models.GeneratedField #1944

Merged
merged 5 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions django-stubs/db/models/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions django-stubs/db/models/fields/generated.pyi
Original file line number Diff line number Diff line change
@@ -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] = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need default values here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

db_returning: Literal[True] = True
_query: Query | None = None
output_field: models.Field | None = 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,
): ...
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
def generated_sql(self, connection: BaseDatabaseWrapper) -> tuple[str, Any]: ...
def db_type_parameters(self, connection: BaseDatabaseWrapper) -> DictWrapper: ...
3 changes: 3 additions & 0 deletions scripts/stubtest/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -299,6 +300,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
Expand All @@ -312,6 +314,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
Expand Down
3 changes: 0 additions & 3 deletions scripts/stubtest/allowlist_todo_django50.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -184,7 +183,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
Expand All @@ -209,7 +207,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
Expand Down