Django

Code

Changeset 6213

Show
Ignore:
Timestamp:
09/14/07 15:36:53 (1 year ago)
Author:
adrian
Message:

Fixed #5460 -- unique_together now accepts a single tuple for convenience. Thanks, Deryck Hodge

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/options.py

    r6195 r6213  
    5353            for attr_name in DEFAULT_NAMES: 
    5454                setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name))) 
     55 
     56            # unique_together can be either a tuple of tuples, or a single 
     57            # tuple of two strings. Normalize it to a tuple of tuples, so that 
     58            # calling code can uniformly expect that. 
     59            ut = meta_attrs.pop('unique_together', getattr(self, 'unique_together')) 
     60            if ut and not isinstance(ut[0], (tuple, list)): 
     61                ut = (ut,) 
     62            setattr(self, 'unique_together', ut) 
     63 
    5564            # verbose_name_plural is a special case because it uses a 's' 
    5665            # by default. 
    5766            setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', string_concat(self.verbose_name, 's'))) 
     67 
    5868            # Any leftover attributes must be invalid. 
    5969            if meta_attrs != {}: 
  • django/trunk/docs/model-api.txt

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