Ticket #5460: unique_together_single_tuple.diff

File unique_together_single_tuple.diff, 1.4 KB (added by deryck, 7 years ago)

A proper patch now, normalizing unique_together to a tuple of tuples

  • django/db/models/options.py

     
    5252            del meta_attrs['__doc__']
    5353            for attr_name in DEFAULT_NAMES:
    5454                setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name)))
     55            # Normalize unique_together to a tuple of tuples
     56            ut = meta_attrs.pop('unique_together', getattr(self, 'unique_together'))
     57            if ut and not isinstance(ut[0], tuple):
     58                ut = (ut,)
     59            setattr(self, 'unique_together', ut)
    5560            # verbose_name_plural is a special case because it uses a 's'
    5661            # by default.
    5762            setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', string_concat(self.verbose_name, 's')))
  • docs/model-api.txt

     
    12241224level (i.e., the appropriate ``UNIQUE`` statements are included in the
    12251225``CREATE TABLE`` statement).
    12261226
     1227**New in Django development version**
     1228
     1229For convenience, unique_together can be a single list when dealing
     1230with a single set of fields::
     1231
     1232        unique_together = ("driver", "restaurant")
     1233
    12271234``verbose_name``
    12281235----------------
    12291236
Back to Top