Fixed #21236 -- Allowed migrations to work with unique_together tuples.

Thanks hjwp for the report.
This commit is contained in:
Javed Khan 2013-10-07 13:07:35 +05:30 committed by Tim Graham
parent 67f5dffbec
commit 4dbd95ad65
3 changed files with 17 additions and 6 deletions

View file

@ -25,6 +25,16 @@ DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering',
'index_together', 'app_cache', 'default_permissions',
'select_on_save')
def normalize_unique_together(unique_together):
"""
unique_together can be either a tuple of tuples, or a single
tuple of two strings. Normalize it to a tuple of tuples, so that
calling code can uniformly expect that.
"""
if unique_together and not isinstance(unique_together[0], (tuple, list)):
unique_together = (unique_together,)
return unique_together
@python_2_unicode_compatible
class Options(object):
def __init__(self, meta, app_label=None):
@ -108,13 +118,8 @@ class Options(object):
setattr(self, attr_name, getattr(self.meta, attr_name))
self.original_attrs[attr_name] = getattr(self, attr_name)
# unique_together can be either a tuple of tuples, or a single
# tuple of two strings. Normalize it to a tuple of tuples, so that
# calling code can uniformly expect that.
ut = meta_attrs.pop('unique_together', self.unique_together)
if ut and not isinstance(ut[0], (tuple, list)):
ut = (ut,)
self.unique_together = ut
self.unique_together = normalize_unique_together(ut)
# verbose_name_plural is a special case because it uses a 's'
# by default.