From 7eec9853006e7f216b45017558a19c6cbdeb9543 Mon Sep 17 00:00:00 2001 From: Kyle Bebak Date: Thu, 29 Aug 2024 18:51:09 -0600 Subject: [PATCH] Add `db_default` arg to `Field` constructors (#263) - Add `db_default` arg to `Field` constructors - This was added in [Django 5.0](https://docs.djangoproject.com/en/5.0/ref/models/fields/#db-default) - Fixes [#252](https://github.com/sbdchd/django-types/issues/252) --- django-stubs/db/models/fields/__init__.pyi | 52 +++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/django-stubs/db/models/fields/__init__.pyi b/django-stubs/db/models/fields/__init__.pyi index 4cb1af1d8..54a809f90 100644 --- a/django-stubs/db/models/fields/__init__.pyi +++ b/django-stubs/db/models/fields/__init__.pyi @@ -9,7 +9,7 @@ from typing_extensions import Literal, Self from django.core.checks import CheckMessage from django.core.exceptions import FieldDoesNotExist as FieldDoesNotExist from django.db.models import Model, TextChoices -from django.db.models.expressions import Col, Combinable +from django.db.models.expressions import Col, Combinable, Func from django.db.models.query_utils import RegisterLookupMixin from django.forms import Widget @@ -59,6 +59,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]): db_comment: str | None column: str default: Any + db_default: Any error_messages: _ErrorMessagesToOverride def __set__(self, instance: Any, value: _ST) -> None: ... # class access @@ -125,6 +126,7 @@ class IntegerField(Generic[_I], Field[_I | Combinable, _I]): null: Literal[False] = ..., db_index: bool = ..., default: _I | Callable[[], _I] | None = ..., + db_default: _I | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -151,6 +153,7 @@ class IntegerField(Generic[_I], Field[_I | Combinable, _I]): null: Literal[True] = ..., db_index: bool = ..., default: _I | Callable[[], _I] = ..., + db_default: _I | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -182,6 +185,7 @@ class PositiveIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField[_I]): null: Literal[False] = ..., db_index: bool = ..., default: _I | Callable[[], _I] | None = ..., + db_default: _I | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -208,6 +212,7 @@ class PositiveIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField[_I]): null: Literal[True] = ..., db_index: bool = ..., default: _I | Callable[[], _I] = ..., + db_default: _I | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -236,6 +241,7 @@ class PositiveSmallIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField[_I]) null: Literal[False] = ..., db_index: bool = ..., default: _I | Callable[[], _I] | None = ..., + db_default: _I | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -261,6 +267,7 @@ class PositiveSmallIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField[_I]) null: Literal[True] = ..., db_index: bool = ..., default: _I | Callable[[], _I] = ..., + db_default: _I | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -289,6 +296,7 @@ class SmallIntegerField(IntegerField[_I]): null: Literal[False] = ..., db_index: bool = ..., default: _I | Callable[[], _I] | None = ..., + db_default: _I | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -315,6 +323,7 @@ class SmallIntegerField(IntegerField[_I]): null: Literal[True] = ..., db_index: bool = ..., default: _I | Callable[[], _I] = ..., + db_default: _I | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -343,6 +352,7 @@ class BigIntegerField(IntegerField[_I]): null: Literal[False] = ..., db_index: bool = ..., default: _I | Callable[[], _I] | None = ..., + db_default: _I | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -369,6 +379,7 @@ class BigIntegerField(IntegerField[_I]): null: Literal[True] = ..., db_index: bool = ..., default: _I | Callable[[], _I] = ..., + db_default: _I | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -397,6 +408,7 @@ class PositiveBigIntegerField(IntegerField[_I]): null: Literal[False] = ..., db_index: bool = ..., default: _I | Callable[[], _I] | None = ..., + db_default: _I | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -423,6 +435,7 @@ class PositiveBigIntegerField(IntegerField[_I]): null: Literal[True] = ..., db_index: bool = ..., default: _I | Callable[[], _I] = ..., + db_default: _I | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -453,6 +466,7 @@ class FloatField(Generic[_F], Field[_F | Combinable, _F]): null: Literal[False] = ..., db_index: bool = ..., default: _F | Callable[[], _F] | None = ..., + db_default: _F | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -479,6 +493,7 @@ class FloatField(Generic[_F], Field[_F | Combinable, _F]): null: Literal[True] = ..., db_index: bool = ..., default: _F | Callable[[], _F] = ..., + db_default: _F | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -514,6 +529,7 @@ class DecimalField(Generic[_DEC], Field[_DEC | Combinable, _DEC]): null: Literal[False] = ..., db_index: bool = ..., default: _DEC | Callable[[], _DEC] | None = ..., + db_default: _DEC | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -544,6 +560,7 @@ class DecimalField(Generic[_DEC], Field[_DEC | Combinable, _DEC]): null: Literal[True] = ..., db_index: bool = ..., default: _DEC | Callable[[], _DEC] = ..., + db_default: _DEC | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -578,6 +595,7 @@ class AutoField(AutoFieldMixin, IntegerField[int], metaclass=AutoFieldMeta): null: bool = ..., db_index: bool = ..., default: int | Callable[[], int] | None = ..., + db_default: int | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -609,6 +627,7 @@ class BigAutoField(AutoFieldMixin, BigIntegerField[int]): null: bool = ..., db_index: bool = ..., default: int | Callable[[], int] | None = ..., + db_default: int | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -640,6 +659,7 @@ class SmallAutoField(AutoFieldMixin, SmallIntegerField[int]): null: bool = ..., db_index: bool = ..., default: int | Callable[[], int] | None = ..., + db_default: int | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -673,6 +693,7 @@ class CharField(Generic[_C], Field[_C | Combinable, _C]): null: Literal[False] = ..., db_index: bool = ..., default: _C | Callable[[], _C] | None = ..., + db_default: _C | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -701,6 +722,7 @@ class CharField(Generic[_C], Field[_C | Combinable, _C]): null: Literal[True] = ..., db_index: bool = ..., default: _C | Callable[[], _C] = ..., + db_default: _C | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -731,6 +753,7 @@ class SlugField(CharField[_C]): null: Literal[False] = ..., db_index: bool = ..., default: _C | Callable[[], _C] | None = ..., + db_default: _C | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -759,6 +782,7 @@ class SlugField(CharField[_C]): null: Literal[True] = ..., db_index: bool = ..., default: _C | Callable[[], _C] = ..., + db_default: _C | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -789,6 +813,7 @@ class EmailField(CharField[_C]): null: Literal[False] = ..., db_index: bool = ..., default: _C | Callable[[], _C] | None = ..., + db_default: _C | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -816,6 +841,7 @@ class EmailField(CharField[_C]): null: Literal[True] = ..., db_index: bool = ..., default: _C | Callable[[], _C] = ..., + db_default: _C | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -845,6 +871,7 @@ class URLField(CharField[_C]): null: Literal[False] = ..., db_index: bool = ..., default: _C | Callable[[], _C] | None = ..., + db_default: _C | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -872,6 +899,7 @@ class URLField(CharField[_C]): null: Literal[True] = ..., db_index: bool = ..., default: _C | Callable[[], _C] = ..., + db_default: _C | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -901,6 +929,7 @@ class TextField(Generic[_C], Field[_C | Combinable, _C]): null: Literal[False] = ..., db_index: bool = ..., default: _C | Callable[[], _C] | None = ..., + db_default: _C | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -928,6 +957,7 @@ class TextField(Generic[_C], Field[_C | Combinable, _C]): null: Literal[True] = ..., db_index: bool = ..., default: _C | Callable[[], _C] = ..., + db_default: _C | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -959,6 +989,7 @@ class BooleanField(Generic[_B], Field[_B | Combinable, _B]): null: Literal[False] = ..., db_index: bool = ..., default: _B | Callable[[], _B] | None = ..., + db_default: _B | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -986,6 +1017,7 @@ class BooleanField(Generic[_B], Field[_B | Combinable, _B]): null: Literal[True] = ..., db_index: bool = ..., default: _B | Callable[[], _B] = ..., + db_default: _B | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1013,6 +1045,7 @@ class IPAddressField(Generic[_C], Field[_C | Combinable, _C]): null: Literal[False] = ..., db_index: bool = ..., default: _C | Callable[[], _C] | None = ..., + db_default: _C | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1039,6 +1072,7 @@ class IPAddressField(Generic[_C], Field[_C | Combinable, _C]): null: Literal[True] = ..., db_index: bool = ..., default: _C | Callable[[], _C] = ..., + db_default: _C | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1072,6 +1106,7 @@ class GenericIPAddressField( null: Literal[False] = ..., db_index: bool = ..., default: _C | Callable[[], _C] | None = ..., + db_default: _C | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1100,6 +1135,7 @@ class GenericIPAddressField( null: Literal[True] = ..., db_index: bool = ..., default: _C | Callable[[], _C] = ..., + db_default: _C | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1137,6 +1173,7 @@ class DateField(DateTimeCheckMixin, Field[_DD | Combinable, _DD]): null: Literal[False] = ..., db_index: bool = ..., default: _DD | Callable[[], _DD] | None = ..., + db_default: _DD | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1167,6 +1204,7 @@ class DateField(DateTimeCheckMixin, Field[_DD | Combinable, _DD]): null: Literal[True] = ..., db_index: bool = ..., default: _DD | Callable[[], _DD] = ..., + db_default: _DD | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1204,6 +1242,7 @@ class TimeField(Generic[_TM], DateTimeCheckMixin, Field[_TM | Combinable, _TM]): null: Literal[False] = ..., db_index: bool = ..., default: _TM | Callable[[], _TM] | None = ..., + db_default: _TM | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1234,6 +1273,7 @@ class TimeField(Generic[_TM], DateTimeCheckMixin, Field[_TM | Combinable, _TM]): null: Literal[True] = ..., db_index: bool = ..., default: _TM | Callable[[], _TM] = ..., + db_default: _TM | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1271,6 +1311,7 @@ class DateTimeField(DateField[_DT]): null: Literal[False] = ..., db_index: bool = ..., default: _DT | Callable[[], _DT] | None = ..., + db_default: _DT | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1301,6 +1342,7 @@ class DateTimeField(DateField[_DT]): null: Literal[True] = ..., db_index: bool = ..., default: _DT | Callable[[], _DT] = ..., + db_default: _DT | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1333,6 +1375,7 @@ class UUIDField(Generic[_U], Field[str | _U, _U]): null: Literal[False] = ..., db_index: bool = ..., default: _U | Callable[[], _U] | None = ..., + db_default: _U | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1359,6 +1402,7 @@ class UUIDField(Generic[_U], Field[str | _U, _U]): null: Literal[True] = ..., db_index: bool = ..., default: _U | Callable[[], _U] = ..., + db_default: _U | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1397,6 +1441,7 @@ class FilePathField(Generic[_C], Field[_C, _C]): null: Literal[False] = ..., db_index: bool = ..., default: _C | Callable[[], _C] | None = ..., + db_default: _C | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1428,6 +1473,7 @@ class FilePathField(Generic[_C], Field[_C, _C]): null: Literal[True] = ..., db_index: bool = ..., default: _C | Callable[[], _C] = ..., + db_default: _C | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1458,6 +1504,7 @@ class BinaryField(Generic[_BIN], Field[_BIN | bytearray | memoryview, _BIN]): null: Literal[False] = ..., db_index: bool = ..., default: _BIN | Callable[[], _BIN] | None = ..., + db_default: _BIN | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1486,6 +1533,7 @@ class BinaryField(Generic[_BIN], Field[_BIN | bytearray | memoryview, _BIN]): null: Literal[True] = ..., db_index: bool = ..., default: _BIN | Callable[[], _BIN] = ..., + db_default: _BIN | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1518,6 +1566,7 @@ class DurationField(Generic[_TD], Field[_TD, _TD]): null: Literal[False] = ..., db_index: bool = ..., default: _TD | Callable[[], _TD] | None = ..., + db_default: _TD | Func | None = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., @@ -1546,6 +1595,7 @@ class DurationField(Generic[_TD], Field[_TD, _TD]): null: Literal[True] = ..., db_index: bool = ..., default: _TD | Callable[[], _TD] = ..., + db_default: _TD | Func = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ...,