Fixed #31538 -- Fixed Meta.ordering validation lookups that are not transforms.
Regression in 440505cb2c
.
Thanks Simon Meers for the report.
This commit is contained in:
parent
d2b9a9fdbb
commit
b73e66e758
|
@ -1747,7 +1747,9 @@ class Model(metaclass=ModelBase):
|
||||||
else:
|
else:
|
||||||
_cls = None
|
_cls = None
|
||||||
except (FieldDoesNotExist, AttributeError):
|
except (FieldDoesNotExist, AttributeError):
|
||||||
if fld is None or fld.get_transform(part) is None:
|
if fld is None or (
|
||||||
|
fld.get_transform(part) is None and fld.get_lookup(part) is None
|
||||||
|
):
|
||||||
errors.append(
|
errors.append(
|
||||||
checks.Error(
|
checks.Error(
|
||||||
"'ordering' refers to the nonexistent field, "
|
"'ordering' refers to the nonexistent field, "
|
||||||
|
|
|
@ -9,4 +9,5 @@ Django 3.0.7 fixes several bugs in 3.0.6.
|
||||||
Bugfixes
|
Bugfixes
|
||||||
========
|
========
|
||||||
|
|
||||||
* ...
|
* Fixed a regression in Django 3.0 by restoring the ability to use field
|
||||||
|
lookups in ``Meta.ordering`` (:ticket:`31538`).
|
||||||
|
|
|
@ -893,6 +893,15 @@ class OtherModelTests(SimpleTestCase):
|
||||||
with register_lookup(models.CharField, Lower):
|
with register_lookup(models.CharField, Lower):
|
||||||
self.assertEqual(Model.check(), [])
|
self.assertEqual(Model.check(), [])
|
||||||
|
|
||||||
|
def test_ordering_pointing_to_lookup_not_transform(self):
|
||||||
|
class Model(models.Model):
|
||||||
|
test = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ('test__isnull',)
|
||||||
|
|
||||||
|
self.assertEqual(Model.check(), [])
|
||||||
|
|
||||||
def test_ordering_pointing_to_related_model_pk(self):
|
def test_ordering_pointing_to_related_model_pk(self):
|
||||||
class Parent(models.Model):
|
class Parent(models.Model):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue