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
ea60b7bc
Kaydet (Commit)
ea60b7bc
authored
Mar 23, 2019
tarafından
Matthias Kestenholz
Kaydeden (comit)
Tim Graham
Mar 23, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Removed redundant model field choices tests.
üst
2ee1e1a1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
8 additions
and
50 deletions
+8
-50
__init__.py
tests/choices/__init__.py
+0
-0
models.py
tests/choices/models.py
+0
-25
tests.py
tests/choices/tests.py
+0
-25
models.py
tests/model_fields/models.py
+2
-0
tests.py
tests/model_fields/tests.py
+6
-0
No files found.
tests/choices/__init__.py
deleted
100644 → 0
Dosyayı görüntüle @
2ee1e1a1
tests/choices/models.py
deleted
100644 → 0
Dosyayı görüntüle @
2ee1e1a1
"""
Specifying 'choices' for a field
Most fields take a ``choices`` parameter, which should be a tuple of tuples
specifying which are the valid values for that field.
For each field that has ``choices``, a model instance gets a
``get_fieldname_display()`` method, where ``fieldname`` is the name of the
field. This method returns the "human-readable" value of the field.
"""
from
django.db
import
models
from
django.utils.translation
import
gettext_lazy
as
_
class
Person
(
models
.
Model
):
GENDER_CHOICES
=
(
(
'M'
,
_
(
'Male'
)),
(
'F'
,
_
(
'Female'
)),
)
name
=
models
.
CharField
(
max_length
=
20
)
gender
=
models
.
CharField
(
max_length
=
1
,
choices
=
GENDER_CHOICES
)
def
__str__
(
self
):
return
self
.
name
tests/choices/tests.py
deleted
100644 → 0
Dosyayı görüntüle @
2ee1e1a1
from
django.test
import
TestCase
from
.models
import
Person
class
ChoicesTests
(
TestCase
):
def
test_display
(
self
):
a
=
Person
.
objects
.
create
(
name
=
'Adrian'
,
gender
=
'M'
)
s
=
Person
.
objects
.
create
(
name
=
'Sara'
,
gender
=
'F'
)
self
.
assertEqual
(
a
.
gender
,
'M'
)
self
.
assertEqual
(
s
.
gender
,
'F'
)
self
.
assertEqual
(
a
.
get_gender_display
(),
'Male'
)
self
.
assertEqual
(
s
.
get_gender_display
(),
'Female'
)
# If the value for the field doesn't correspond to a valid choice,
# the value itself is provided as a display value.
a
.
gender
=
''
self
.
assertEqual
(
a
.
get_gender_display
(),
''
)
a
.
gender
=
'U'
self
.
assertEqual
(
a
.
get_gender_display
(),
'U'
)
# _get_FIELD_display() coerces lazy strings.
self
.
assertIsInstance
(
a
.
get_gender_display
(),
str
)
tests/model_fields/models.py
Dosyayı görüntüle @
ea60b7bc
...
...
@@ -12,6 +12,7 @@ from django.db.models.fields.files import ImageField, ImageFieldFile
from
django.db.models.fields.related
import
(
ForeignKey
,
ForeignObject
,
ManyToManyField
,
OneToOneField
,
)
from
django.utils.translation
import
gettext_lazy
as
_
try
:
from
PIL
import
Image
...
...
@@ -46,6 +47,7 @@ class Whiz(models.Model):
)
),
(
0
,
'Other'
),
(
5
,
_
(
'translated'
)),
)
c
=
models
.
IntegerField
(
choices
=
CHOICES
,
null
=
True
)
...
...
tests/model_fields/tests.py
Dosyayı görüntüle @
ea60b7bc
...
...
@@ -162,6 +162,12 @@ class GetFieldDisplayTests(SimpleTestCase):
self
.
assertEqual
(
Whiz
(
c
=
''
)
.
get_c_display
(),
''
)
# Empty value
self
.
assertEqual
(
WhizDelayed
(
c
=
0
)
.
get_c_display
(),
'Other'
)
# Delayed choices
def
test_get_FIELD_display_translated
(
self
):
"""A translated display value is coerced to str."""
val
=
Whiz
(
c
=
5
)
.
get_c_display
()
self
.
assertIsInstance
(
val
,
str
)
self
.
assertEqual
(
val
,
'translated'
)
def
test_iterator_choices
(
self
):
"""
get_choices() works with Iterators.
...
...
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