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
c03e4171
Unverified
Kaydet (Commit)
c03e4171
authored
May 30, 2018
tarafından
Tim Graham
Kaydeden (comit)
GitHub
May 30, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #28748 -- Reallowed lazy model field choices.
Regression in
3aa9ab39
.
üst
3dffcb55
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
3 deletions
+10
-3
__init__.py
django/db/models/fields/__init__.py
+3
-3
test_ordinary_fields.py
tests/invalid_models_tests/test_ordinary_fields.py
+7
-0
No files found.
django/db/models/fields/__init__.py
Dosyayı görüntüle @
c03e4171
...
@@ -244,10 +244,10 @@ class Field(RegisterLookupMixin):
...
@@ -244,10 +244,10 @@ class Field(RegisterLookupMixin):
if
not
self
.
choices
:
if
not
self
.
choices
:
return
[]
return
[]
def
is_value
(
value
):
def
is_value
(
value
,
accept_promise
=
True
):
return
isinstance
(
value
,
(
str
,
Promise
))
or
not
is_iterable
(
value
)
return
isinstance
(
value
,
(
str
,
Promise
)
if
accept_promise
else
str
)
or
not
is_iterable
(
value
)
if
is_value
(
self
.
choices
):
if
is_value
(
self
.
choices
,
accept_promise
=
False
):
return
[
return
[
checks
.
Error
(
checks
.
Error
(
"'choices' must be an iterable (e.g., a list or tuple)."
,
"'choices' must be an iterable (e.g., a list or tuple)."
,
...
...
tests/invalid_models_tests/test_ordinary_fields.py
Dosyayı görüntüle @
c03e4171
...
@@ -4,6 +4,7 @@ from django.core.checks import Error, Warning as DjangoWarning
...
@@ -4,6 +4,7 @@ from django.core.checks import Error, Warning as DjangoWarning
from
django.db
import
connection
,
models
from
django.db
import
connection
,
models
from
django.test
import
SimpleTestCase
,
TestCase
,
skipIfDBFeature
from
django.test
import
SimpleTestCase
,
TestCase
,
skipIfDBFeature
from
django.test.utils
import
isolate_apps
,
override_settings
from
django.test.utils
import
isolate_apps
,
override_settings
from
django.utils.functional
import
lazy
from
django.utils.timezone
import
now
from
django.utils.timezone
import
now
from
django.utils.translation
import
gettext_lazy
as
_
from
django.utils.translation
import
gettext_lazy
as
_
...
@@ -188,6 +189,12 @@ class CharFieldTests(TestCase):
...
@@ -188,6 +189,12 @@ class CharFieldTests(TestCase):
self
.
assertEqual
(
Model
.
_meta
.
get_field
(
'field'
)
.
check
(),
[])
self
.
assertEqual
(
Model
.
_meta
.
get_field
(
'field'
)
.
check
(),
[])
def
test_lazy_choices
(
self
):
class
Model
(
models
.
Model
):
field
=
models
.
CharField
(
max_length
=
10
,
choices
=
lazy
(
lambda
:
[[
1
,
'1'
],
[
2
,
'2'
]],
tuple
)())
self
.
assertEqual
(
Model
.
_meta
.
get_field
(
'field'
)
.
check
(),
[])
def
test_choices_named_group
(
self
):
def
test_choices_named_group
(
self
):
class
Model
(
models
.
Model
):
class
Model
(
models
.
Model
):
field
=
models
.
CharField
(
field
=
models
.
CharField
(
...
...
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