diff -r 31cfaa8a671b tests/modeltests/model_forms/models.py
|
a
|
b
|
|
| 272 | 272 | slug = models.CharField(max_length=50, unique_for_year='posted', blank=True) |
| 273 | 273 | subtitle = models.CharField(max_length=50, unique_for_month='posted', blank=True) |
| 274 | 274 | posted = models.DateField(blank=True, null=True) |
| | 275 | |
| | 276 | @python_2_unicode_compatible |
| | 277 | class Seller(models.Model) : |
| | 278 | name = models.CharField(max_length=50) |
| | 279 | |
| | 280 | def __iter__(self) : |
| | 281 | for item in self.items.all() : |
| | 282 | yield item |
| | 283 | |
| | 284 | def __str__(self) : |
| | 285 | return self.name |
| | 286 | |
| | 287 | class Antique(models.Model) : |
| | 288 | owner = models.ForeignKey(Seller, related_name='items') |
| | 289 | name = models.CharField(max_length=50) |
| | 290 | |
| | 291 | class Auction(models.Model) : |
| | 292 | location = models.CharField(max_length=50) |
| | 293 | sellers = models.ManyToManyField(Seller) |
diff -r 31cfaa8a671b tests/modeltests/model_forms/tests.py
|
a
|
b
|
|
| 17 | 17 | Category, CommaSeparatedInteger, CustomFieldForExclusionModel, DerivedBook, |
| 18 | 18 | DerivedPost, ExplicitPK, FlexibleDatePost, ImprovedArticle, |
| 19 | 19 | ImprovedArticleWithParentLink, Inventory, PhoneNumber, Post, Price, |
| 20 | | Product, TextFile, Writer, WriterProfile, test_images) |
| | 20 | Product, TextFile, Writer, WriterProfile, Seller, Antique, Auction, |
| | 21 | test_images) |
| 21 | 22 | |
| 22 | 23 | if test_images: |
| 23 | 24 | from .models import ImageFile, OptionalImageFile |
| … |
… |
|
| 176 | 177 | model = Price |
| 177 | 178 | exclude = ('quantity',) |
| 178 | 179 | |
| | 180 | class AuctionForm(forms.ModelForm) : |
| | 181 | class Meta: |
| | 182 | model = Auction |
| 179 | 183 | |
| 180 | 184 | class ModelFormBaseTest(TestCase): |
| 181 | 185 | def test_base_form(self): |
| … |
… |
|
| 1484 | 1488 | ['name']) |
| 1485 | 1489 | self.assertHTMLEqual(six.text_type(CustomFieldForExclusionForm()), |
| 1486 | 1490 | '''<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="10" /></td></tr>''') |
| | 1491 | |
| | 1492 | def test_iterable_model_m2m(self) : |
| | 1493 | john = Seller.objects.create(name='John Smith') |
| | 1494 | jane = Seller.objects.create(name='Jane Smith') |
| | 1495 | chair = Antique.objects.create(name='Victorian armchair', owner=john) |
| | 1496 | table = Antique.objects.create(name='Victorian table', owner=john) |
| | 1497 | bowl = Antique.objects.create(name='Mayan medicine bowl', owner=jane) |
| | 1498 | form = AuctionForm() |
| | 1499 | self.assertHTMLEqual(form.as_p(), """<p><label for="id_location">Location:</label> <input id="id_location" type="text" name="location" maxlength="50" /></p> |
| | 1500 | <p><label for="id_sellers">Sellers:</label> <select multiple="multiple" name="sellers" id="id_sellers"> |
| | 1501 | <option value="1">John Smith</option> |
| | 1502 | <option value="2">Jane Smith</option> |
| | 1503 | </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></p>""") |