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
This commit is contained in:
parent
3da4c0ab92
commit
9cccf59db5
|
@ -52,9 +52,19 @@ class Options(object):
|
||||||
del meta_attrs['__doc__']
|
del meta_attrs['__doc__']
|
||||||
for attr_name in DEFAULT_NAMES:
|
for attr_name in DEFAULT_NAMES:
|
||||||
setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name)))
|
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'
|
# verbose_name_plural is a special case because it uses a 's'
|
||||||
# by default.
|
# by default.
|
||||||
setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', string_concat(self.verbose_name, 's')))
|
setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', string_concat(self.verbose_name, 's')))
|
||||||
|
|
||||||
# Any leftover attributes must be invalid.
|
# Any leftover attributes must be invalid.
|
||||||
if meta_attrs != {}:
|
if meta_attrs != {}:
|
||||||
raise TypeError, "'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())
|
raise TypeError, "'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())
|
||||||
|
|
|
@ -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
|
level (i.e., the appropriate ``UNIQUE`` statements are included in the
|
||||||
``CREATE TABLE`` statement).
|
``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")
|
||||||
|
|
||||||
``verbose_name``
|
``verbose_name``
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue