1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #18172 -- Made models with __iter__ usable in ModelMultipleChoiceField

Thanks to Patryk Zawadzki for the patch.
This commit is contained in:
Patryk Zawadzki
2012-12-19 19:12:08 +01:00
committed by Anssi Kääriäinen
parent abd0f304b1
commit 3989ce52ef
3 changed files with 33 additions and 2 deletions

View File

@@ -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>""")