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
a7bc00e1
Kaydet (Commit)
a7bc00e1
authored
Mar 29, 2015
tarafından
Christopher Luc
Kaydeden (comit)
Tim Graham
Nis 10, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24514 -- Made migration writer omit models import if it's unused.
üst
d5d92260
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
writer.py
django/db/migrations/writer.py
+10
-2
test_writer.py
tests/migrations/test_writer.py
+16
-0
No files found.
django/db/migrations/writer.py
Dosyayı görüntüle @
a7bc00e1
...
...
@@ -158,7 +158,7 @@ class MigrationWriter(object):
"replaces_str"
:
""
,
}
imports
=
{
"from django.db import migrations, models"
}
imports
=
set
()
# Deconstruct operations
operations
=
[]
...
...
@@ -188,7 +188,15 @@ class MigrationWriter(object):
migration_imports
.
add
(
line
.
split
(
"import"
)[
1
]
.
strip
())
imports
.
remove
(
line
)
self
.
needs_manual_porting
=
True
imports
.
discard
(
"from django.db import models"
)
# django.db.migrations is always used, but models import may not be.
# If models import exists, merge it with migrations import.
if
"from django.db import models"
in
imports
:
imports
.
discard
(
"from django.db import models"
)
imports
.
add
(
"from django.db import migrations, models"
)
else
:
imports
.
add
(
"from django.db import migrations"
)
# Sort imports by the package / module to be imported (the part after
# "from" in "from ... import ..." or after "import" in "import ...").
sorted_imports
=
sorted
(
imports
,
key
=
lambda
i
:
i
.
split
()[
1
])
...
...
tests/migrations/test_writer.py
Dosyayı görüntüle @
a7bc00e1
...
...
@@ -512,6 +512,22 @@ class WriterTests(TestCase):
output
)
def
test_models_import_omitted
(
self
):
"""
django.db.models shouldn't be imported if unused.
"""
migration
=
type
(
str
(
"Migration"
),
(
migrations
.
Migration
,),
{
"operations"
:
[
migrations
.
AlterModelOptions
(
name
=
'model'
,
options
=
{
'verbose_name'
:
'model'
,
'verbose_name_plural'
:
'models'
},
),
]
})
writer
=
MigrationWriter
(
migration
)
output
=
writer
.
as_string
()
.
decode
(
'utf-8'
)
self
.
assertIn
(
"from django.db import migrations
\n
"
,
output
)
def
test_deconstruct_class_arguments
(
self
):
# Yes, it doesn't make sense to use a class as a default for a
# CharField. It does make sense for custom fields though, for example
...
...
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