summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-05-01 03:21:54 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-05-01 03:21:54 +0000
commitd943f5ae927cfa99d5fe70e70350c8b4df3e3269 (patch)
tree042ea613f2dc819a7f9cc0d00916dcf970232ade /django
parent0b2f9e89cdca3f4e05c160537119a7e7f390c187 (diff)
Fixed #4130 -- Added more self-explanatory error message when a typo is made in
a queryset field argument. We may need to fine-tune the error message based on experience down the line, but this stands as an improvement on its own. Thanks, Ned Batchelder. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5133 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/db/models/query.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 91f54e48b9..06163677d4 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -853,6 +853,13 @@ def find_field(name, field_list, related_query):
return None
return matches[0]
+def field_choices(field_list, related_query):
+ if related_query:
+ choices = [f.field.related_query_name() for f in field_list]
+ else:
+ choices = [f.name for f in field_list]
+ return choices
+
def lookup_inner(path, lookup_type, value, opts, table, column):
qn = backend.quote_name
joins, where, params = SortedDict(), [], []
@@ -937,7 +944,11 @@ def lookup_inner(path, lookup_type, value, opts, table, column):
except FieldFound: # Match found, loop has been shortcut.
pass
else: # No match found.
- raise TypeError, "Cannot resolve keyword '%s' into field" % name
+ choices = field_choices(current_opts.many_to_many, False) + \
+ field_choices(current_opts.get_all_related_many_to_many_objects(), True) + \
+ field_choices(current_opts.get_all_related_objects(), True) + \
+ field_choices(current_opts.fields, False)
+ raise TypeError, "Cannot resolve keyword '%s' into field, choices are: %s" % (name, ", ".join(choices))
# Check whether an intermediate join is required between current_table
# and new_table.