summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-09-14 20:36:53 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-09-14 20:36:53 +0000
commit9cccf59db53e4b793e6932a01acb1b990fa87257 (patch)
tree82defedddb4f36584d89b8267c8ce76aee902046 /django
parent3da4c0ab9292e8e3378b7314174f0bbcc4e692d1 (diff)
Fixed #5460 -- unique_together now accepts a single tuple for convenience. Thanks, Deryck Hodge
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6213 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/db/models/options.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 502cbc4a65..788d1c80de 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -52,9 +52,19 @@ class Options(object):
del meta_attrs['__doc__']
for attr_name in DEFAULT_NAMES:
setattr(self, attr_name, meta_attrs.pop(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', getattr(self, 'unique_together'))
+ if ut and not isinstance(ut[0], (tuple, list)):
+ ut = (ut,)
+ setattr(self, 'unique_together', ut)
+
# verbose_name_plural is a special case because it uses a 's'
# by default.
setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', string_concat(self.verbose_name, 's')))
+
# Any leftover attributes must be invalid.
if meta_attrs != {}:
raise TypeError, "'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())