@@ -1511,8 +1511,9 @@ def test_auto_id(self):
15111511<li>The URL: <input type="text" name="url" maxlength="40" required></li>""" ,
15121512 )
15131513
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 ()
15161517 # Initial values can be provided for model forms
15171518 f = ArticleForm (
15181519 auto_id = False ,
@@ -1623,6 +1624,26 @@ def test_initial_values(self):
16231624 test_art = Article .objects .get (id = art_id_1 )
16241625 self .assertEqual (test_art .headline , "Test headline" )
16251626
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+
16261647 def test_m2m_initial_callable (self ):
16271648 """
16281649 A callable can be provided as the initial value for an m2m field.
0 commit comments