summaryrefslogtreecommitdiff
path: root/django/db/models
diff options
context:
space:
mode:
authorAnubhav Joshi <anubhav9042@gmail.com>2014-03-02 00:36:15 +0530
committerTim Graham <timograham@gmail.com>2014-03-01 15:44:42 -0500
commitbb2ca9fe6cdd490526b44b30f207c8f743bfaa84 (patch)
tree8e448c5f136ad0160d062bc65e23bc107cee656c /django/db/models
parent3273bd7b254680a5b241e2fdbc3196956b2b44e8 (diff)
Fixed #22172 -- Allowed index_together to be a single list (rather than list of lists)..
Thanks EmilStenstrom for the suggestion.
Diffstat (limited to 'django/db/models')
-rw-r--r--django/db/models/options.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/django/db/models/options.py b/django/db/models/options.py
index ebbb19f479..4e0307fc4f 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -24,24 +24,26 @@ DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering',
'select_on_save')
-def normalize_unique_together(unique_together):
+def normalize_together(option_together):
"""
- unique_together can be either a tuple of tuples, or a single
+ option_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.
"""
try:
- if not unique_together:
+ if not option_together:
return ()
- first_element = next(iter(unique_together))
+ if not isinstance(option_together, (tuple, list)):
+ raise TypeError
+ first_element = next(iter(option_together))
if not isinstance(first_element, (tuple, list)):
- unique_together = (unique_together,)
+ option_together = (option_together,)
# Normalize everything to tuples
- return tuple(tuple(ut) for ut in unique_together)
+ return tuple(tuple(ot) for ot in option_together)
except TypeError:
- # If the value of unique_together isn't valid, return it
+ # If the value of option_together isn't valid, return it
# verbatim; this will be picked up by the check framework later.
- return unique_together
+ return option_together
@python_2_unicode_compatible
@@ -140,7 +142,10 @@ class Options(object):
self.original_attrs[attr_name] = getattr(self, attr_name)
ut = meta_attrs.pop('unique_together', self.unique_together)
- self.unique_together = normalize_unique_together(ut)
+ self.unique_together = normalize_together(ut)
+
+ it = meta_attrs.pop('index_together', self.index_together)
+ self.index_together = normalize_together(it)
# verbose_name_plural is a special case because it uses a 's'
# by default.