1
0
mirror of https://github.com/django/django.git synced 2025-07-06 18:59:13 +00:00

queryset-refactor: Allow exclusions when bumping the aliases on a subquery.

git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7288 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2008-03-18 13:53:22 +00:00
parent bec21f0e2b
commit 150b7ac770

View File

@ -652,7 +652,7 @@ class Query(object):
data[LHS_ALIAS] = change_map[lhs] data[LHS_ALIAS] = change_map[lhs]
self.alias_map[alias] = tuple(data) self.alias_map[alias] = tuple(data)
def bump_prefix(self): def bump_prefix(self, exceptions=()):
""" """
Changes the alias prefix to the next letter in the alphabet and Changes the alias prefix to the next letter in the alphabet and
relabels all the aliases. Even tables that previously had no alias will relabels all the aliases. Even tables that previously had no alias will
@ -661,12 +661,17 @@ class Query(object):
Subclasses who create their own prefix should override this method to Subclasses who create their own prefix should override this method to
produce a similar result (a new prefix and relabelled aliases). produce a similar result (a new prefix and relabelled aliases).
The 'exceptions' parameter is a container that holds alias names which
should not be changed.
""" """
assert ord(self.alias_prefix) < ord('Z') assert ord(self.alias_prefix) < ord('Z')
self.alias_prefix = chr(ord(self.alias_prefix) + 1) self.alias_prefix = chr(ord(self.alias_prefix) + 1)
change_map = {} change_map = {}
prefix = self.alias_prefix prefix = self.alias_prefix
for pos, alias in enumerate(self.tables): for pos, alias in enumerate(self.tables):
if alias in exceptions:
continue
new_alias = '%s%d' % (prefix, pos) new_alias = '%s%d' % (prefix, pos)
change_map[alias] = new_alias change_map[alias] = new_alias
self.tables[pos] = new_alias self.tables[pos] = new_alias