Refs #29598 -- Removed FloatRangeField per deprecation timeline.
This commit is contained in:
parent
416c584cab
commit
b47bb4c4a7
|
@ -11,7 +11,6 @@ from .utils import AttributeSetter
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'RangeField', 'IntegerRangeField', 'BigIntegerRangeField',
|
'RangeField', 'IntegerRangeField', 'BigIntegerRangeField',
|
||||||
'DecimalRangeField', 'DateTimeRangeField', 'DateRangeField',
|
'DecimalRangeField', 'DateTimeRangeField', 'DateRangeField',
|
||||||
'FloatRangeField',
|
|
||||||
'RangeBoundary', 'RangeOperators',
|
'RangeBoundary', 'RangeOperators',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -135,22 +134,6 @@ class DecimalRangeField(RangeField):
|
||||||
return 'numrange'
|
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
|
|
||||||
|
|
||||||
def db_type(self, connection):
|
|
||||||
return 'numrange'
|
|
||||||
|
|
||||||
|
|
||||||
class DateTimeRangeField(RangeField):
|
class DateTimeRangeField(RangeField):
|
||||||
base_field = models.DateTimeField
|
base_field = models.DateTimeField
|
||||||
range_type = DateTimeTZRange
|
range_type = DateTimeTZRange
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
import warnings
|
|
||||||
|
|
||||||
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
|
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core import exceptions
|
from django.core import exceptions
|
||||||
from django.forms.widgets import MultiWidget
|
from django.forms.widgets import MultiWidget
|
||||||
from django.utils.deprecation import RemovedInDjango31Warning
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'BaseRangeField', 'IntegerRangeField', 'DecimalRangeField',
|
'BaseRangeField', 'IntegerRangeField', 'DecimalRangeField',
|
||||||
'DateTimeRangeField', 'DateRangeField', 'FloatRangeField', 'RangeWidget',
|
'DateTimeRangeField', 'DateRangeField', 'RangeWidget',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,17 +72,6 @@ class DecimalRangeField(BaseRangeField):
|
||||||
range_type = NumericRange
|
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):
|
class DateTimeRangeField(BaseRangeField):
|
||||||
default_error_messages = {'invalid': _('Enter two valid date/times.')}
|
default_error_messages = {'invalid': _('Enter two valid date/times.')}
|
||||||
base_field = forms.DateTimeField
|
base_field = forms.DateTimeField
|
||||||
|
|
|
@ -174,7 +174,7 @@ Model fields
|
||||||
* **fields.E901**: ``CommaSeparatedIntegerField`` is removed except for support
|
* **fields.E901**: ``CommaSeparatedIntegerField`` is removed except for support
|
||||||
in historical migrations.
|
in historical migrations.
|
||||||
* **fields.W902**: ``FloatRangeField`` is deprecated and will be removed in
|
* **fields.W902**: ``FloatRangeField`` is deprecated and will be removed in
|
||||||
Django 3.1.
|
Django 3.1. *This check appeared in Django 2.2 and 3.0*.
|
||||||
|
|
||||||
File fields
|
File fields
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
|
@ -661,19 +661,6 @@ excluded; that is, ``[)``.
|
||||||
the database and a :class:`~psycopg2:psycopg2.extras.NumericRange` in
|
the database and a :class:`~psycopg2:psycopg2.extras.NumericRange` in
|
||||||
Python.
|
Python.
|
||||||
|
|
||||||
``FloatRangeField``
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
.. class:: FloatRangeField(**options)
|
|
||||||
|
|
||||||
Stores a range of floating point values. Based on a
|
|
||||||
:class:`~django.db.models.FloatField`. Represented by a ``numrange`` in the
|
|
||||||
database and a :class:`~psycopg2:psycopg2.extras.NumericRange` in Python.
|
|
||||||
|
|
||||||
.. deprecated:: 2.2
|
|
||||||
|
|
||||||
Use :class:`DecimalRangeField` instead.
|
|
||||||
|
|
||||||
``DateTimeRangeField``
|
``DateTimeRangeField``
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -201,19 +201,6 @@ not greater than the upper bound. All of these fields use
|
||||||
:class:`~psycopg2:psycopg2.extras.NumericRange`. Default for
|
:class:`~psycopg2:psycopg2.extras.NumericRange`. Default for
|
||||||
:class:`~django.contrib.postgres.fields.DecimalRangeField`.
|
:class:`~django.contrib.postgres.fields.DecimalRangeField`.
|
||||||
|
|
||||||
``FloatRangeField``
|
|
||||||
~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
.. class:: FloatRangeField
|
|
||||||
|
|
||||||
Based on :class:`~django.forms.FloatField` and translates its input into
|
|
||||||
:class:`~psycopg2:psycopg2.extras.NumericRange`. Default for
|
|
||||||
:class:`~django.contrib.postgres.fields.FloatRangeField`.
|
|
||||||
|
|
||||||
.. deprecated:: 2.2
|
|
||||||
|
|
||||||
Use :class:`DecimalRangeField` instead.
|
|
||||||
|
|
||||||
``DateTimeRangeField``
|
``DateTimeRangeField``
|
||||||
~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -230,4 +230,5 @@ in Django 3.1.
|
||||||
See :ref:`deprecated-features-2.2` for details on these changes, including how
|
See :ref:`deprecated-features-2.2` for details on these changes, including how
|
||||||
to remove usage of these features.
|
to remove usage of these features.
|
||||||
|
|
||||||
* ...
|
* ``django.contrib.postgres.fields.FloatRangeField`` and
|
||||||
|
``django.contrib.postgres.forms.FloatRangeField`` are removed.
|
||||||
|
|
|
@ -5,9 +5,8 @@ from decimal import Decimal
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core import exceptions, serializers
|
from django.core import exceptions, serializers
|
||||||
from django.db.models import DateField, DateTimeField, F, Func, Value
|
from django.db.models import DateField, DateTimeField, F, Func, Value
|
||||||
from django.test import ignore_warnings, override_settings
|
from django.test import override_settings
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.deprecation import RemovedInDjango31Warning
|
|
||||||
|
|
||||||
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
|
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
|
||||||
from .models import RangeLookupsModel, RangesModel
|
from .models import RangeLookupsModel, RangesModel
|
||||||
|
@ -445,22 +444,11 @@ class TestFormField(PostgreSQLSimpleTestCase):
|
||||||
value = field.clean(['1', '2'])
|
value = field.clean(['1', '2'])
|
||||||
self.assertEqual(value, NumericRange(1, 2))
|
self.assertEqual(value, NumericRange(1, 2))
|
||||||
|
|
||||||
@ignore_warnings(category=RemovedInDjango31Warning)
|
|
||||||
def test_valid_floats(self):
|
|
||||||
field = pg_forms.FloatRangeField()
|
|
||||||
value = field.clean(['1.12345', '2.001'])
|
|
||||||
self.assertEqual(value, NumericRange(1.12345, 2.001))
|
|
||||||
|
|
||||||
def test_valid_decimal(self):
|
def test_valid_decimal(self):
|
||||||
field = pg_forms.DecimalRangeField()
|
field = pg_forms.DecimalRangeField()
|
||||||
value = field.clean(['1.12345', '2.001'])
|
value = field.clean(['1.12345', '2.001'])
|
||||||
self.assertEqual(value, NumericRange(Decimal('1.12345'), Decimal('2.001')))
|
self.assertEqual(value, NumericRange(Decimal('1.12345'), Decimal('2.001')))
|
||||||
|
|
||||||
def test_float_range_field_deprecation(self):
|
|
||||||
msg = 'FloatRangeField is deprecated in favor of DecimalRangeField.'
|
|
||||||
with self.assertRaisesMessage(RemovedInDjango31Warning, msg):
|
|
||||||
pg_forms.FloatRangeField()
|
|
||||||
|
|
||||||
def test_valid_timestamps(self):
|
def test_valid_timestamps(self):
|
||||||
field = pg_forms.DateTimeRangeField()
|
field = pg_forms.DateTimeRangeField()
|
||||||
value = field.clean(['01/01/2014 00:00:00', '02/02/2014 12:12:12'])
|
value = field.clean(['01/01/2014 00:00:00', '02/02/2014 12:12:12'])
|
||||||
|
|
Loading…
Reference in New Issue