magic-removal: Modified query lookup to correctly handle non-plural RelatedObjects.
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2145 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
90a49140a5
commit
ce71979e53
|
@ -234,12 +234,16 @@ class FieldFound(Exception):
|
|||
"Exception used to short circuit field-finding operations."
|
||||
pass
|
||||
|
||||
def find_field(name, field_list):
|
||||
def find_field(name, field_list, use_accessor=False):
|
||||
"""
|
||||
Finds a field with a specific name in a list of field instances.
|
||||
Returns None if there are no matches, or several matches.
|
||||
"""
|
||||
matches = [f for f in field_list if f.name == name]
|
||||
|
||||
if use_accessor:
|
||||
matches = [f for f in field_list if f.OLD_get_accessor_name() == name]
|
||||
else:
|
||||
matches = [f for f in field_list if f.name == name]
|
||||
if len(matches) != 1:
|
||||
return None
|
||||
return matches[0]
|
||||
|
@ -293,7 +297,7 @@ def lookup_inner(path, clause, value, opts, table, column):
|
|||
raise FieldFound
|
||||
|
||||
# Does the name belong to a one-to-many field?
|
||||
field = find_field(name, opts.get_all_related_objects())
|
||||
field = find_field(name, current_opts.get_all_related_objects(), True)
|
||||
if field:
|
||||
new_table = table + LOOKUP_SEPARATOR + name
|
||||
new_opts = field.opts
|
||||
|
|
|
@ -8,7 +8,7 @@ from django.db.models import *
|
|||
|
||||
class Parent(Model):
|
||||
name = CharField(maxlength=100)
|
||||
bestchild = ForeignKey("Child", null=True)
|
||||
bestchild = ForeignKey("Child", null=True, related_name="favoured_by")
|
||||
|
||||
class Child(Model):
|
||||
name = CharField(maxlength=100)
|
||||
|
|
Loading…
Reference in New Issue