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
3989ce52
Kaydet (Commit)
3989ce52
authored
Ara 19, 2012
tarafından
Patryk Zawadzki
Kaydeden (comit)
Anssi Kääriäinen
Ara 19, 2012
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #18172 -- Made models with __iter__ usable in ModelMultipleChoiceField
Thanks to Patryk Zawadzki for the patch.
üst
abd0f304
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
2 deletions
+33
-2
models.py
django/forms/models.py
+3
-1
models.py
tests/modeltests/model_forms/models.py
+15
-0
tests.py
tests/modeltests/model_forms/tests.py
+15
-1
No files found.
django/forms/models.py
Dosyayı görüntüle @
3989ce52
...
...
@@ -1033,6 +1033,8 @@ class ModelMultipleChoiceField(ModelChoiceField):
return
qs
def
prepare_value
(
self
,
value
):
if
hasattr
(
value
,
'__iter__'
)
and
not
isinstance
(
value
,
six
.
text_type
):
if
(
hasattr
(
value
,
'__iter__'
)
and
not
isinstance
(
value
,
six
.
text_type
)
and
not
hasattr
(
value
,
'_meta'
)):
return
[
super
(
ModelMultipleChoiceField
,
self
)
.
prepare_value
(
v
)
for
v
in
value
]
return
super
(
ModelMultipleChoiceField
,
self
)
.
prepare_value
(
value
)
tests/modeltests/model_forms/models.py
Dosyayı görüntüle @
3989ce52
...
...
@@ -263,3 +263,18 @@ class FlexibleDatePost(models.Model):
slug
=
models
.
CharField
(
max_length
=
50
,
unique_for_year
=
'posted'
,
blank
=
True
)
subtitle
=
models
.
CharField
(
max_length
=
50
,
unique_for_month
=
'posted'
,
blank
=
True
)
posted
=
models
.
DateField
(
blank
=
True
,
null
=
True
)
@python_2_unicode_compatible
class
Colour
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
def
__iter__
(
self
):
for
number
in
xrange
(
5
):
yield
number
def
__str__
(
self
):
return
self
.
name
class
ColourfulItem
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
colours
=
models
.
ManyToManyField
(
Colour
)
tests/modeltests/model_forms/tests.py
Dosyayı görüntüle @
3989ce52
...
...
@@ -19,7 +19,8 @@ from .models import (Article, ArticleStatus, BetterWriter, BigInt, Book,
Category
,
CommaSeparatedInteger
,
CustomFieldForExclusionModel
,
DerivedBook
,
DerivedPost
,
ExplicitPK
,
FlexibleDatePost
,
ImprovedArticle
,
ImprovedArticleWithParentLink
,
Inventory
,
Post
,
Price
,
Product
,
TextFile
,
Writer
,
WriterProfile
,
test_images
)
Product
,
TextFile
,
Writer
,
WriterProfile
,
Colour
,
ColourfulItem
,
test_images
)
if
test_images
:
from
.models
import
ImageFile
,
OptionalImageFile
...
...
@@ -174,6 +175,10 @@ class PriceFormWithoutQuantity(forms.ModelForm):
model
=
Price
exclude
=
(
'quantity'
,)
class
ColourfulItemForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
ColourfulItem
class
ModelFormBaseTest
(
TestCase
):
def
test_base_form
(
self
):
...
...
@@ -1518,3 +1523,12 @@ class OldFormForXTests(TestCase):
[
'name'
])
self
.
assertHTMLEqual
(
six
.
text_type
(
CustomFieldForExclusionForm
()),
'''<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="10" /></td></tr>'''
)
def
test_iterable_model_m2m
(
self
)
:
colour
=
Colour
.
objects
.
create
(
name
=
'Blue'
)
form
=
ColourfulItemForm
()
self
.
maxDiff
=
1024
self
.
assertHTMLEqual
(
form
.
as_p
(),
"""<p><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" maxlength="50" /></p>
<p><label for="id_colours">Colours:</label> <select multiple="multiple" name="colours" id="id_colours">
<option value="1">Blue</option>
</select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></p>"""
)
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