Made `pk` a generic expansion for the primary key, rather than just an expansion for __id__exact.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3826 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2006-09-25 13:49:01 +00:00
parent f6ec6d24ab
commit 0c41869e6c
4 changed files with 22 additions and 10 deletions

View file

@ -712,14 +712,10 @@ def parse_lookup(kwarg_items, opts):
# Extract the last elements of the kwarg.
# The very-last is the lookup_type (equals, like, etc).
# The second-last is the table column on which the lookup_type is
# to be performed.
# The exceptions to this are:
# 1) "pk", which is an implicit id__exact;
# if we find "pk", make the lookup_type "exact', and insert
# a dummy name of None, which we will replace when
# we know which table column to grab as the primary key.
# 2) If there is only one part, or the last part is not a query
# term, assume that the query is an __exact
# to be performed. If this name is 'pk', it will be substituted with
# the name of the primary key.
# If there is only one part, or the last part is not a query
# term, assume that the query is an __exact
lookup_type = path.pop()
if lookup_type == 'pk':
lookup_type = 'exact'
@ -766,7 +762,7 @@ def lookup_inner(path, lookup_type, value, opts, table, column):
name = path.pop(0)
# Has the primary key been requested? If so, expand it out
# to be the name of the current class' primary key
if name is None:
if name is None or name == 'pk':
name = current_opts.pk.name
# Try to find the name in the fields associated with the current class