(self)
| 1513 | ) |
| 1514 | |
| 1515 | def test_initial_values(self): |
| 1516 | self.create_basic_data() |
| 1517 | # Initial values can be provided for model forms |
| 1518 | f = ArticleForm( |
| 1519 | auto_id=False, |
| 1520 | initial={ |
| 1521 | "headline": "Your headline here", |
| 1522 | "categories": [str(self.c1.id), str(self.c2.id)], |
| 1523 | }, |
| 1524 | ) |
| 1525 | self.assertHTMLEqual( |
| 1526 | f.as_ul(), |
| 1527 | """ |
| 1528 | <li>Headline: |
| 1529 | <input type="text" name="headline" value="Your headline here" maxlength="50" |
| 1530 | required> |
| 1531 | </li> |
| 1532 | <li>Slug: <input type="text" name="slug" maxlength="50" required></li> |
| 1533 | <li>Pub date: <input type="text" name="pub_date" required></li> |
| 1534 | <li>Writer: <select name="writer" required> |
| 1535 | <option value="" selected>- Select an option -</option> |
| 1536 | <option value="%s">Bob Woodward</option> |
| 1537 | <option value="%s">Mike Royko</option> |
| 1538 | </select></li> |
| 1539 | <li>Article: |
| 1540 | <textarea rows="10" cols="40" name="article" required></textarea></li> |
| 1541 | <li>Categories: <select multiple name="categories"> |
| 1542 | <option value="%s" selected>Entertainment</option> |
| 1543 | <option value="%s" selected>It's a test</option> |
| 1544 | <option value="%s">Third test</option> |
| 1545 | </select></li> |
| 1546 | <li>Status: <select name="status"> |
| 1547 | <option value="" selected>- Select an option -</option> |
| 1548 | <option value="1">Draft</option> |
| 1549 | <option value="2">Pending</option> |
| 1550 | <option value="3">Live</option> |
| 1551 | </select></li> |
| 1552 | """ |
| 1553 | % (self.w_woodward.pk, self.w_royko.pk, self.c1.pk, self.c2.pk, self.c3.pk), |
| 1554 | ) |
| 1555 | |
| 1556 | # When the ModelForm is passed an instance, that instance's current |
| 1557 | # values are inserted as 'initial' data in each Field. |
| 1558 | f = RoykoForm(auto_id=False, instance=self.w_royko) |
| 1559 | self.assertHTMLEqual( |
| 1560 | str(f), |
| 1561 | '<div>Name:<div class="helptext">Use both first and last names.</div>' |
| 1562 | '<input type="text" name="name" value="Mike Royko" maxlength="50" ' |
| 1563 | "required></div>", |
| 1564 | ) |
| 1565 | |
| 1566 | art = Article.objects.create( |
| 1567 | headline="Test article", |
| 1568 | slug="test-article", |
| 1569 | pub_date=datetime.date(1988, 1, 4), |
| 1570 | writer=self.w_royko, |
| 1571 | article="Hello.", |
| 1572 | ) |
nothing calls this directly
no test coverage detected