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
f7e90711
Kaydet (Commit)
f7e90711
authored
Tem 07, 2016
tarafından
Akshesh
Kaydeden (comit)
Tim Graham
Tem 07, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #26709 -- Added IndexOperation to avoid code duplication.
üst
b1e7d19d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
9 deletions
+17
-9
models.py
django/db/migrations/operations/models.py
+17
-9
No files found.
django/db/migrations/operations/models.py
Dosyayı görüntüle @
f7e90711
...
...
@@ -744,7 +744,15 @@ class AlterModelManagers(ModelOptionOperation):
return
"Change managers on
%
s"
%
(
self
.
name
,
)
class
AddIndex
(
Operation
):
class
IndexOperation
(
Operation
):
option_name
=
'indexes'
@cached_property
def
model_name_lower
(
self
):
return
self
.
model_name
.
lower
()
class
AddIndex
(
IndexOperation
):
"""
Add an index on a model.
"""
...
...
@@ -759,9 +767,9 @@ class AddIndex(Operation):
self
.
index
=
index
def
state_forwards
(
self
,
app_label
,
state
):
model_state
=
state
.
models
[
app_label
,
self
.
model_name
.
lower
()
]
model_state
=
state
.
models
[
app_label
,
self
.
model_name
_lower
]
self
.
index
.
model
=
state
.
apps
.
get_model
(
app_label
,
self
.
model_name
)
model_state
.
options
[
'indexes'
]
.
append
(
self
.
index
)
model_state
.
options
[
self
.
option_name
]
.
append
(
self
.
index
)
def
database_forwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
schema_editor
.
add_index
(
self
.
index
)
...
...
@@ -787,7 +795,7 @@ class AddIndex(Operation):
)
class
RemoveIndex
(
Operation
):
class
RemoveIndex
(
Index
Operation
):
"""
Remove an index from a model.
"""
...
...
@@ -797,17 +805,17 @@ class RemoveIndex(Operation):
self
.
name
=
name
def
state_forwards
(
self
,
app_label
,
state
):
model_state
=
state
.
models
[
app_label
,
self
.
model_name
.
lower
()
]
indexes
=
model_state
.
options
[
'indexes'
]
model_state
.
options
[
'indexes'
]
=
[
idx
for
idx
in
indexes
if
idx
.
name
!=
self
.
name
]
model_state
=
state
.
models
[
app_label
,
self
.
model_name
_lower
]
indexes
=
model_state
.
options
[
self
.
option_name
]
model_state
.
options
[
self
.
option_name
]
=
[
idx
for
idx
in
indexes
if
idx
.
name
!=
self
.
name
]
def
database_forwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
from_model_state
=
from_state
.
models
[
app_label
,
self
.
model_name
.
lower
()
]
from_model_state
=
from_state
.
models
[
app_label
,
self
.
model_name
_lower
]
index
=
from_model_state
.
get_index_by_name
(
self
.
name
)
schema_editor
.
remove_index
(
index
)
def
database_backwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
to_model_state
=
to_state
.
models
[
app_label
,
self
.
model_name
.
lower
()
]
to_model_state
=
to_state
.
models
[
app_label
,
self
.
model_name
_lower
]
index
=
to_model_state
.
get_index_by_name
(
self
.
name
)
schema_editor
.
add_index
(
index
)
...
...
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