summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
Diffstat (limited to 'django')
-rw-r--r--django/contrib/postgres/apps.py2
-rw-r--r--django/contrib/postgres/fields/ranges.py19
-rw-r--r--django/contrib/postgres/forms/ranges.py22
3 files changed, 37 insertions, 6 deletions
diff --git a/django/contrib/postgres/apps.py b/django/contrib/postgres/apps.py
index 1ab5074f19..f1ec09806a 100644
--- a/django/contrib/postgres/apps.py
+++ b/django/contrib/postgres/apps.py
@@ -19,7 +19,7 @@ class PostgresConfig(AppConfig):
conn.introspection.data_types_reverse.update({
3802: 'django.contrib.postgres.fields.JSONField',
3904: 'django.contrib.postgres.fields.IntegerRangeField',
- 3906: 'django.contrib.postgres.fields.FloatRangeField',
+ 3906: 'django.contrib.postgres.fields.DecimalRangeField',
3910: 'django.contrib.postgres.fields.DateTimeRangeField',
3912: 'django.contrib.postgres.fields.DateRangeField',
3926: 'django.contrib.postgres.fields.BigIntegerRangeField',
diff --git a/django/contrib/postgres/fields/ranges.py b/django/contrib/postgres/fields/ranges.py
index 0bb914d383..74ba4eb230 100644
--- a/django/contrib/postgres/fields/ranges.py
+++ b/django/contrib/postgres/fields/ranges.py
@@ -10,7 +10,8 @@ from .utils import AttributeSetter
__all__ = [
'RangeField', 'IntegerRangeField', 'BigIntegerRangeField',
- 'FloatRangeField', 'DateTimeRangeField', 'DateRangeField',
+ 'DecimalRangeField', 'DateTimeRangeField', 'DateRangeField',
+ 'FloatRangeField',
]
@@ -100,7 +101,23 @@ class BigIntegerRangeField(RangeField):
return 'int8range'
+class DecimalRangeField(RangeField):
+ base_field = models.DecimalField
+ range_type = NumericRange
+ form_field = forms.DecimalRangeField
+
+ def db_type(self, connection):
+ return 'numrange'
+
+
class FloatRangeField(RangeField):
+ system_check_deprecated_details = {
+ 'msg': (
+ 'FloatRangeField is deprecated and will be removed in Django 3.1.'
+ ),
+ 'hint': 'Use DecimalRangeField instead.',
+ 'id': 'fields.W902',
+ }
base_field = models.FloatField
range_type = NumericRange
form_field = forms.FloatRangeField
diff --git a/django/contrib/postgres/forms/ranges.py b/django/contrib/postgres/forms/ranges.py
index 5f2b2434a3..c36bec8479 100644
--- a/django/contrib/postgres/forms/ranges.py
+++ b/django/contrib/postgres/forms/ranges.py
@@ -1,13 +1,16 @@
+import warnings
+
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
from django import forms
from django.core import exceptions
from django.forms.widgets import MultiWidget
+from django.utils.deprecation import RemovedInDjango31Warning
from django.utils.translation import gettext_lazy as _
__all__ = [
- 'BaseRangeField', 'IntegerRangeField', 'FloatRangeField',
- 'DateTimeRangeField', 'DateRangeField', 'RangeWidget',
+ 'BaseRangeField', 'IntegerRangeField', 'DecimalRangeField',
+ 'DateTimeRangeField', 'DateRangeField', 'FloatRangeField', 'RangeWidget',
]
@@ -66,12 +69,23 @@ class IntegerRangeField(BaseRangeField):
range_type = NumericRange
-class FloatRangeField(BaseRangeField):
+class DecimalRangeField(BaseRangeField):
default_error_messages = {'invalid': _('Enter two numbers.')}
- base_field = forms.FloatField
+ base_field = forms.DecimalField
range_type = NumericRange
+class FloatRangeField(DecimalRangeField):
+ base_field = forms.FloatField
+
+ def __init__(self, **kwargs):
+ warnings.warn(
+ 'FloatRangeField is deprecated in favor of DecimalRangeField.',
+ RemovedInDjango31Warning, stacklevel=2,
+ )
+ super().__init__(**kwargs)
+
+
class DateTimeRangeField(BaseRangeField):
default_error_messages = {'invalid': _('Enter two valid date/times.')}
base_field = forms.DateTimeField