Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
4dbd95ad
Kaydet (Commit)
4dbd95ad
authored
Eki 07, 2013
tarafından
Javed Khan
Kaydeden (comit)
Tim Graham
Eki 07, 2013
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #21236 -- Allowed migrations to work with unique_together tuples.
Thanks hjwp for the report.
üst
67f5dffb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
6 deletions
+17
-6
models.py
django/db/migrations/operations/models.py
+2
-0
options.py
django/db/models/options.py
+11
-6
test_operations.py
tests/migrations/test_operations.py
+4
-0
No files found.
django/db/migrations/operations/models.py
Dosyayı görüntüle @
4dbd95ad
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
):
...
...
django/db/models/options.py
Dosyayı görüntüle @
4dbd95ad
...
...
@@ -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.
...
...
tests/migrations/test_operations.py
Dosyayı görüntüle @
4dbd95ad
...
...
@@ -267,6 +267,10 @@ class OperationTests(MigrationTestBase):
cursor
.
execute
(
"INSERT INTO test_alunto_pony (id, pink, weight) VALUES (1, 1, 1)"
)
cursor
.
execute
(
"INSERT INTO test_alunto_pony (id, pink, weight) VALUES (2, 1, 1)"
)
cursor
.
execute
(
"DELETE FROM test_alunto_pony"
)
# Test flat unique_together
operation
=
migrations
.
AlterUniqueTogether
(
"Pony"
,
(
"pink"
,
"weight"
))
operation
.
state_forwards
(
"test_alunto"
,
new_state
)
self
.
assertEqual
(
len
(
new_state
.
models
[
"test_alunto"
,
"pony"
]
.
options
.
get
(
"unique_together"
,
set
())),
1
)
def
test_alter_index_together
(
self
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment