mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
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
This commit is contained in:
parent
0b2f9e89cd
commit
d943f5ae92
6 changed files with 19 additions and 8 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue