summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2019-03-01 19:38:21 +0100
committerGitHub <noreply@github.com>2019-03-01 19:38:21 +0100
commitf69c7bbdceba43789bfba935dd8fa3daaa7f36c4 (patch)
tree2b7d33d38832de4631694390630acc48a37fd4d5
parentfe65918dca405644047b7dbc295d14535626a83a (diff)
Refs #29408 -- Cosmetic edits for validation of related fields and lookups in model Meta.ordering.
Follow up to 440505cb2cadbe1a5b9fba246bcde6c04f51d07e.
-rw-r--r--django/db/models/base.py7
-rw-r--r--docs/ref/checks.txt2
-rw-r--r--tests/invalid_models_tests/test_models.py17
-rw-r--r--tests/postgres_tests/test_json.py2
4 files changed, 16 insertions, 12 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 7e4fa9ac68..2884679ba1 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -1643,7 +1643,7 @@ class Model(metaclass=ModelBase):
# Convert "-field" to "field".
fields = ((f[1:] if f.startswith('-') else f) for f in fields)
- # Separate related field and non related fields.
+ # Separate related fields and non-related fields.
_fields = []
related_fields = []
for f in fields:
@@ -1667,7 +1667,7 @@ class Model(metaclass=ModelBase):
errors.append(
checks.Error(
"'ordering' refers to the nonexistent field, "
- "related field or lookup '%s'." % field,
+ "related field, or lookup '%s'." % field,
obj=cls,
id='models.E015',
)
@@ -1693,7 +1693,8 @@ class Model(metaclass=ModelBase):
for invalid_field in invalid_fields:
errors.append(
checks.Error(
- "'ordering' refers to the nonexistent field '%s'." % invalid_field,
+ "'ordering' refers to the nonexistent field, related "
+ "field, or lookup '%s'." % invalid_field,
obj=cls,
id='models.E015',
)
diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt
index 0b9fd39eb9..2e00de454b 100644
--- a/docs/ref/checks.txt
+++ b/docs/ref/checks.txt
@@ -277,7 +277,7 @@ Models
supported for that option.
* **models.E014**: ``ordering`` must be a tuple or list (even if you want to
order by only one field).
-* **models.E015**: ``ordering`` refers to the nonexistent field, related field
+* **models.E015**: ``ordering`` refers to the nonexistent field, related field,
or lookup ``<field name>``.
* **models.E016**: ``indexes/index_together/unique_together`` refers to field
``<field_name>`` which is not local to model ``<model>``.
diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py
index 320e799a6e..6b57dd7d9d 100644
--- a/tests/invalid_models_tests/test_models.py
+++ b/tests/invalid_models_tests/test_models.py
@@ -632,7 +632,8 @@ class OtherModelTests(SimpleTestCase):
self.assertEqual(Model.check(), [
Error(
- "'ordering' refers to the nonexistent field 'relation'.",
+ "'ordering' refers to the nonexistent field, related field, "
+ "or lookup 'relation'.",
obj=Model,
id='models.E015',
),
@@ -645,7 +646,8 @@ class OtherModelTests(SimpleTestCase):
self.assertEqual(Model.check(), [
Error(
- "'ordering' refers to the nonexistent field 'missing_field'.",
+ "'ordering' refers to the nonexistent field, related field, "
+ "or lookup 'missing_field'.",
obj=Model,
id='models.E015',
)
@@ -660,7 +662,8 @@ class OtherModelTests(SimpleTestCase):
self.assertEqual(Model.check(), [
Error(
- "'ordering' refers to the nonexistent field 'missing_fk_field_id'.",
+ "'ordering' refers to the nonexistent field, related field, "
+ "or lookup 'missing_fk_field_id'.",
obj=Model,
id='models.E015',
)
@@ -675,7 +678,7 @@ class OtherModelTests(SimpleTestCase):
self.assertEqual(Model.check(), [
Error(
- "'ordering' refers to the nonexistent field, related field "
+ "'ordering' refers to the nonexistent field, related field, "
"or lookup 'missing_related__id'.",
obj=Model,
id='models.E015',
@@ -694,7 +697,7 @@ class OtherModelTests(SimpleTestCase):
self.assertEqual(Child.check(), [
Error(
- "'ordering' refers to the nonexistent field, related field "
+ "'ordering' refers to the nonexistent field, related field, "
"or lookup 'parent__missing_field'.",
obj=Child,
id='models.E015',
@@ -710,7 +713,7 @@ class OtherModelTests(SimpleTestCase):
self.assertEqual(Child.check(), [
Error(
- "'ordering' refers to the nonexistent field, related field "
+ "'ordering' refers to the nonexistent field, related field, "
"or lookup 'parent__missing_field'.",
obj=Child,
id='models.E015',
@@ -732,7 +735,7 @@ class OtherModelTests(SimpleTestCase):
self.assertEqual(Child.check(), [
Error(
- "'ordering' refers to the nonexistent field, related field "
+ "'ordering' refers to the nonexistent field, related field, "
"or lookup 'parent1__parent2__missing_field'.",
obj=Child,
id='models.E015',
diff --git a/tests/postgres_tests/test_json.py b/tests/postgres_tests/test_json.py
index e95939be16..ca164a81ba 100644
--- a/tests/postgres_tests/test_json.py
+++ b/tests/postgres_tests/test_json.py
@@ -19,7 +19,7 @@ except ImportError:
pass
-class TestModelMetaOrdering(PostgreSQLTestCase):
+class TestModelMetaOrdering(PostgreSQLSimpleTestCase):
def test_ordering_by_json_field_value(self):
class TestJSONModel(JSONModel):
class Meta: