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