Skip to content
Browse files

Fixed #5460 -- unique_together now accepts a single tuple for conveni…

…ence. Thanks, Deryck Hodge

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 3da4c0a commit 9cccf59db53e4b793e6932a01acb1b990fa87257 @adrianholovaty adrianholovaty committed
Showing with 17 additions and 0 deletions.
  1. +10 −0 django/db/models/
  2. +7 −0 docs/model-api.txt
10 django/db/models/
@@ -52,9 +52,19 @@ def contribute_to_class(self, cls, name):
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())
7 docs/model-api.txt
@@ -1226,6 +1226,13 @@ together. It's used in the Django admin and is enforced at the database
level (i.e., the appropriate ``UNIQUE`` statements are included in the
``CREATE TABLE`` statement).
+**New in Django development version**
+For convenience, unique_together can be a single list when dealing
+with a single set of fields::
+ unique_together = ("driver", "restaurant")

0 comments on commit 9cccf59

Please sign in to comment.
Something went wrong with that request. Please try again.