diff options
| author | Javed Khan <javed@agiliq.com> | 2013-10-07 13:07:35 +0530 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-10-07 09:39:14 -0400 |
| commit | 4dbd95ad65fa3fc86af7391b28a759b401f530d1 (patch) | |
| tree | 1155fef29bc442a562804bf1027d00481e5d97ca /django | |
| parent | 67f5dffbec366ed50264d32c25facd2681105258 (diff) | |
Fixed #21236 -- Allowed migrations to work with unique_together tuples.
Thanks hjwp for the report.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/migrations/operations/models.py | 2 | ||||
| -rw-r--r-- | django/db/models/options.py | 17 |
2 files changed, 13 insertions, 6 deletions
diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py index b86c0776c1..c5d40c0387 100644 --- a/django/db/migrations/operations/models.py +++ b/django/db/migrations/operations/models.py @@ -1,5 +1,6 @@ from .base import Operation from django.db import models, router +from django.db.models.options import normalize_unique_together from django.db.migrations.state import ModelState @@ -108,6 +109,7 @@ class AlterUniqueTogether(Operation): def __init__(self, name, unique_together): self.name = name + unique_together = normalize_unique_together(unique_together) self.unique_together = set(tuple(cons) for cons in unique_together) def state_forwards(self, app_label, state): diff --git a/django/db/models/options.py b/django/db/models/options.py index 8e0e1a2210..523ca1a7bf 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -25,6 +25,16 @@ DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering', 'index_together', 'app_cache', 'default_permissions', 'select_on_save') +def normalize_unique_together(unique_together): + """ + 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. + """ + if unique_together and not isinstance(unique_together[0], (tuple, list)): + unique_together = (unique_together,) + return unique_together + @python_2_unicode_compatible class Options(object): def __init__(self, meta, app_label=None): @@ -108,13 +118,8 @@ class Options(object): setattr(self, attr_name, getattr(self.meta, attr_name)) self.original_attrs[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', self.unique_together) - if ut and not isinstance(ut[0], (tuple, list)): - ut = (ut,) - self.unique_together = ut + self.unique_together = normalize_unique_together(ut) # verbose_name_plural is a special case because it uses a 's' # by default. |
