@@ -1511,8 +1511,9 @@ def test_auto_id(self):
1511
1511
<li>The URL: <input type="text" name="url" maxlength="40" required></li>""" ,
1512
1512
)
1513
1513
1514
- def test_initial_values (self ):
1515
- self .create_basic_data ()
1514
+ def test_initial_values (self , create_data = True ):
1515
+ if create_data :
1516
+ self .create_basic_data ()
1516
1517
# Initial values can be provided for model forms
1517
1518
f = ArticleForm (
1518
1519
auto_id = False ,
@@ -1623,6 +1624,26 @@ def test_initial_values(self):
1623
1624
test_art = Article .objects .get (id = art_id_1 )
1624
1625
self .assertEqual (test_art .headline , "Test headline" )
1625
1626
1627
+ def test_int_pks (self ):
1628
+ """
1629
+ ObjectIdAutoField supports numeric pks in ModelForm data, not just
1630
+ ObjectId.
1631
+ """
1632
+ # The following lines repeat self.create_initial_data() but with
1633
+ # manually assigned pks.
1634
+ self .c1 = Category .objects .create (
1635
+ pk = 1 , name = "Entertainment" , slug = "entertainment" , url = "entertainment"
1636
+ )
1637
+ self .c2 = Category .objects .create (
1638
+ pk = 2 , name = "It's a test" , slug = "its-test" , url = "test"
1639
+ )
1640
+ self .c3 = Category .objects .create (
1641
+ pk = 3 , name = "Third test" , slug = "third-test" , url = "third"
1642
+ )
1643
+ self .w_royko = Writer .objects .create (name = "Mike Royko" , pk = 1 )
1644
+ self .w_woodward = Writer .objects .create (name = "Bob Woodward" , pk = 2 )
1645
+ self .test_initial_values (create_data = False )
1646
+
1626
1647
def test_m2m_initial_callable (self ):
1627
1648
"""
1628
1649
A callable can be provided as the initial value for an m2m field.
0 commit comments