Loading django/db/models/fields/related.py +6 −1 Original line number Diff line number Diff line Loading @@ -1766,7 +1766,12 @@ class ForeignObject(RelatedField): root_constraint = constraint_class() assert len(targets) == len(sources) if len(lookups) > 1: raise exceptions.FieldError('Relation fields do not support nested lookups') raise exceptions.FieldError( "Cannot resolve keyword %r into field. Choices are: %s" % ( lookups[0], ", ".join(f.name for f in self.model._meta.get_fields()), ) ) lookup_type = lookups[0] def get_normalized_value(value): Loading tests/queries/tests.py +9 −0 Original line number Diff line number Diff line Loading @@ -1164,6 +1164,15 @@ class Queries1Tests(BaseQuerysetTest): ['<Author: a1>', '<Author: a2>', '<Author: a3>', '<Author: a4>'] ) def test_lookup_constraint_fielderror(self): msg = ( "Cannot resolve keyword 'unknown_field' into field. Choices are: " "annotation, category, category_id, children, id, item, " "managedmodel, name, parent, parent_id" ) with self.assertRaisesMessage(FieldError, msg): Tag.objects.filter(unknown_field__name='generic') class Queries2Tests(TestCase): @classmethod Loading Loading
django/db/models/fields/related.py +6 −1 Original line number Diff line number Diff line Loading @@ -1766,7 +1766,12 @@ class ForeignObject(RelatedField): root_constraint = constraint_class() assert len(targets) == len(sources) if len(lookups) > 1: raise exceptions.FieldError('Relation fields do not support nested lookups') raise exceptions.FieldError( "Cannot resolve keyword %r into field. Choices are: %s" % ( lookups[0], ", ".join(f.name for f in self.model._meta.get_fields()), ) ) lookup_type = lookups[0] def get_normalized_value(value): Loading
tests/queries/tests.py +9 −0 Original line number Diff line number Diff line Loading @@ -1164,6 +1164,15 @@ class Queries1Tests(BaseQuerysetTest): ['<Author: a1>', '<Author: a2>', '<Author: a3>', '<Author: a4>'] ) def test_lookup_constraint_fielderror(self): msg = ( "Cannot resolve keyword 'unknown_field' into field. Choices are: " "annotation, category, category_id, children, id, item, " "managedmodel, name, parent, parent_id" ) with self.assertRaisesMessage(FieldError, msg): Tag.objects.filter(unknown_field__name='generic') class Queries2Tests(TestCase): @classmethod Loading