mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-08 21:14:49 +08:00
@@ -2,6 +2,8 @@ from typing import Any
|
|||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange # type: ignore
|
||||||
|
|
||||||
class RangeField(models.Field):
|
class RangeField(models.Field):
|
||||||
empty_strings_allowed: bool = ...
|
empty_strings_allowed: bool = ...
|
||||||
base_field: Any = ...
|
base_field: Any = ...
|
||||||
@@ -10,8 +12,17 @@ class RangeField(models.Field):
|
|||||||
def to_python(self, value: Any): ...
|
def to_python(self, value: Any): ...
|
||||||
def value_to_string(self, obj: Any): ...
|
def value_to_string(self, obj: Any): ...
|
||||||
|
|
||||||
class IntegerRangeField(RangeField): ...
|
class IntegerRangeField(RangeField):
|
||||||
class BigIntegerRangeField(RangeField): ...
|
def __get__(self, instance, owner) -> NumericRange: ...
|
||||||
class FloatRangeField(RangeField): ...
|
|
||||||
class DateTimeRangeField(RangeField): ...
|
class BigIntegerRangeField(RangeField):
|
||||||
class DateRangeField(RangeField): ...
|
def __get__(self, instance, owner) -> NumericRange: ...
|
||||||
|
|
||||||
|
class FloatRangeField(RangeField):
|
||||||
|
def __get__(self, instance, owner) -> NumericRange: ...
|
||||||
|
|
||||||
|
class DateTimeRangeField(RangeField):
|
||||||
|
def __get__(self, instance, owner) -> DateTimeTZRange: ...
|
||||||
|
|
||||||
|
class DateRangeField(RangeField):
|
||||||
|
def __get__(self, instance, owner) -> DateRange: ...
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from typing import Any, Optional, Tuple, Iterable, Callable, Dict, Union, Type
|
from typing import Any, Optional, Tuple, Iterable, Callable, Dict, Union, Type
|
||||||
|
import decimal
|
||||||
|
|
||||||
from django.db.models import Model
|
from django.db.models import Model
|
||||||
from django.db.models.query_utils import RegisterLookupMixin
|
from django.db.models.query_utils import RegisterLookupMixin
|
||||||
@@ -67,7 +68,7 @@ class SmallIntegerField(IntegerField): ...
|
|||||||
class BigIntegerField(IntegerField): ...
|
class BigIntegerField(IntegerField): ...
|
||||||
class FloatField(Field): ...
|
class FloatField(Field): ...
|
||||||
|
|
||||||
class DecimalField(IntegerField):
|
class DecimalField(Field):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
verbose_name: Optional[str] = ...,
|
verbose_name: Optional[str] = ...,
|
||||||
@@ -90,6 +91,7 @@ class DecimalField(IntegerField):
|
|||||||
validators: Iterable[_ValidatorCallable] = ...,
|
validators: Iterable[_ValidatorCallable] = ...,
|
||||||
error_messages: Optional[_ErrorMessagesToOverride] = ...,
|
error_messages: Optional[_ErrorMessagesToOverride] = ...,
|
||||||
): ...
|
): ...
|
||||||
|
def __get__(self, instance, owner) -> decimal.Decimal: ...
|
||||||
|
|
||||||
class AutoField(Field):
|
class AutoField(Field):
|
||||||
def __get__(self, instance, owner) -> int: ...
|
def __get__(self, instance, owner) -> int: ...
|
||||||
|
|||||||
@@ -37,6 +37,21 @@ reveal_type(user.name) # E: Revealed type is 'builtins.str'
|
|||||||
reveal_type(user.slug) # E: Revealed type is 'builtins.str'
|
reveal_type(user.slug) # E: Revealed type is 'builtins.str'
|
||||||
reveal_type(user.text) # E: Revealed type is 'builtins.str'
|
reveal_type(user.text) # E: Revealed type is 'builtins.str'
|
||||||
|
|
||||||
|
[CASE test_model_field_classes_from_exciting_locations]
|
||||||
|
from django.db import models
|
||||||
|
from django.contrib.postgres import fields as pg_fields
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
|
class Booking(models.Model):
|
||||||
|
id = models.AutoField(primary_key=True)
|
||||||
|
time_range = pg_fields.DateTimeRangeField(null=False)
|
||||||
|
some_decimal = models.DecimalField(max_digits=10, decimal_places=5)
|
||||||
|
|
||||||
|
booking = Booking()
|
||||||
|
reveal_type(booking.id) # E: Revealed type is 'builtins.int'
|
||||||
|
reveal_type(booking.time_range) # E: Revealed type is 'Any'
|
||||||
|
reveal_type(booking.some_decimal) # E: Revealed type is 'decimal.Decimal'
|
||||||
|
|
||||||
[CASE test_add_id_field_if_no_primary_key_defined]
|
[CASE test_add_id_field_if_no_primary_key_defined]
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user