Ticket #10992: 10992-fix_and_tests-v2.diff

File 10992-fix_and_tests-v2.diff, 8.6 KB (added by Zain Memon, 16 years ago)

Fix incorporating russellm's suggestions in comment 8 + uncommenting the tests from [10725]

  • django/forms/models.py

     
    612612        for form in self.initial_forms:
    613613            pk_name = self._pk_field.name
    614614            raw_pk_value = form._raw_value(pk_name)
    615             pk_value = form.fields[pk_name].clean(raw_pk_value).pk
     615
     616            if hasattr(form.fields[pk_name].clean(raw_pk_value), 'pk'):
     617                pk_value = form.fields[pk_name].clean(raw_pk_value).pk
     618            else:
     619                pk_value = form.fields[pk_name].clean(raw_pk_value)
     620               
    616621            obj = existing_objects[pk_value]
    617622            if self.can_delete:
    618623                raw_delete_value = form._raw_value(DELETION_FIELD_NAME)
  • tests/regressiontests/admin_views/tests.py

     
    13261326        self.failUnlessEqual(Grommet.objects.count(), 1)
    13271327        self.failUnlessEqual(Grommet.objects.all()[0].name, "Grommet 1 Updated")
    13281328
    1329     # def test_char_pk_inline(self):
    1330     #     "A model with a character PK can be saved as inlines. Regression for #10992"
    1331     #     # First add a new inline
    1332     #     self.post_data['doohickey_set-0-code'] = "DH1"
    1333     #     self.post_data['doohickey_set-0-name'] = "Doohickey 1"
    1334     #     response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
    1335     #     self.failUnlessEqual(response.status_code, 302)
    1336     #     self.failUnlessEqual(DooHickey.objects.count(), 1)
    1337     #     self.failUnlessEqual(DooHickey.objects.all()[0].name, "Doohickey 1")
    1338     #
    1339     #     # Check that the PK link exists on the rendered form
    1340     #     response = self.client.get('/test_admin/admin/admin_views/collector/1/')
    1341     #     self.assertContains(response, 'name="doohickey_set-0-code"')
    1342     #
    1343     #     # Now resave that inline
    1344     #     self.post_data['doohickey_set-INITIAL_FORMS'] = "1"
    1345     #     self.post_data['doohickey_set-0-code'] = "DH1"
    1346     #     self.post_data['doohickey_set-0-name'] = "Doohickey 1"
    1347     #     response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
    1348     #     self.failUnlessEqual(response.status_code, 302)
    1349     #     self.failUnlessEqual(DooHickey.objects.count(), 1)
    1350     #     self.failUnlessEqual(DooHickey.objects.all()[0].name, "Doohickey 1")
    1351     #
    1352     #     # Now modify that inline
    1353     #     self.post_data['doohickey_set-INITIAL_FORMS'] = "1"
    1354     #     self.post_data['doohickey_set-0-code'] = "DH1"
    1355     #     self.post_data['doohickey_set-0-name'] = "Doohickey 1 Updated"
    1356     #     response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
    1357     #     self.failUnlessEqual(response.status_code, 302)
    1358     #     self.failUnlessEqual(DooHickey.objects.count(), 1)
    1359     #     self.failUnlessEqual(DooHickey.objects.all()[0].name, "Doohickey 1 Updated")
     1329    def test_char_pk_inline(self):
     1330        "A model with a character PK can be saved as inlines. Regression for #10992"
     1331        # First add a new inline
     1332        self.post_data['doohickey_set-0-code'] = "DH1"
     1333        self.post_data['doohickey_set-0-name'] = "Doohickey 1"
     1334        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
     1335        self.failUnlessEqual(response.status_code, 302)
     1336        self.failUnlessEqual(DooHickey.objects.count(), 1)
     1337        self.failUnlessEqual(DooHickey.objects.all()[0].name, "Doohickey 1")
     1338   
     1339        # Check that the PK link exists on the rendered form
     1340        response = self.client.get('/test_admin/admin/admin_views/collector/1/')
     1341        self.assertContains(response, 'name="doohickey_set-0-code"')
     1342   
     1343        # Now resave that inline
     1344        self.post_data['doohickey_set-INITIAL_FORMS'] = "1"
     1345        self.post_data['doohickey_set-0-code'] = "DH1"
     1346        self.post_data['doohickey_set-0-name'] = "Doohickey 1"
     1347        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
     1348        self.failUnlessEqual(response.status_code, 302)
     1349        self.failUnlessEqual(DooHickey.objects.count(), 1)
     1350        self.failUnlessEqual(DooHickey.objects.all()[0].name, "Doohickey 1")
     1351   
     1352        # Now modify that inline
     1353        self.post_data['doohickey_set-INITIAL_FORMS'] = "1"
     1354        self.post_data['doohickey_set-0-code'] = "DH1"
     1355        self.post_data['doohickey_set-0-name'] = "Doohickey 1 Updated"
     1356        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
     1357        self.failUnlessEqual(response.status_code, 302)
     1358        self.failUnlessEqual(DooHickey.objects.count(), 1)
     1359        self.failUnlessEqual(DooHickey.objects.all()[0].name, "Doohickey 1 Updated")
     1360   
     1361    def test_integer_pk_inline(self):
     1362        "A model with an integer PK can be saved as inlines. Regression for #10992"
     1363        # First add a new inline
     1364        self.post_data['whatsit_set-0-index'] = "42"
     1365        self.post_data['whatsit_set-0-name'] = "Whatsit 1"
     1366        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
     1367        self.failUnlessEqual(response.status_code, 302)
     1368        self.failUnlessEqual(Whatsit.objects.count(), 1)
     1369        self.failUnlessEqual(Whatsit.objects.all()[0].name, "Whatsit 1")
     1370   
     1371        # Check that the PK link exists on the rendered form
     1372        response = self.client.get('/test_admin/admin/admin_views/collector/1/')
     1373        self.assertContains(response, 'name="whatsit_set-0-index"')
     1374   
     1375        # Now resave that inline
     1376        self.post_data['whatsit_set-INITIAL_FORMS'] = "1"
     1377        self.post_data['whatsit_set-0-index'] = "42"
     1378        self.post_data['whatsit_set-0-name'] = "Whatsit 1"
     1379        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
     1380        self.failUnlessEqual(response.status_code, 302)
     1381        self.failUnlessEqual(Whatsit.objects.count(), 1)
     1382        self.failUnlessEqual(Whatsit.objects.all()[0].name, "Whatsit 1")
     1383   
     1384        # Now modify that inline
     1385        self.post_data['whatsit_set-INITIAL_FORMS'] = "1"
     1386        self.post_data['whatsit_set-0-index'] = "42"
     1387        self.post_data['whatsit_set-0-name'] = "Whatsit 1 Updated"
     1388        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
     1389        self.failUnlessEqual(response.status_code, 302)
     1390        self.failUnlessEqual(Whatsit.objects.count(), 1)
     1391        self.failUnlessEqual(Whatsit.objects.all()[0].name, "Whatsit 1 Updated")
    13601392
    1361     # def test_integer_pk_inline(self):
    1362     #     "A model with an integer PK can be saved as inlines. Regression for #10992"
    1363     #     # First add a new inline
    1364     #     self.post_data['whatsit_set-0-index'] = "42"
    1365     #     self.post_data['whatsit_set-0-name'] = "Whatsit 1"
    1366     #     response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
    1367     #     self.failUnlessEqual(response.status_code, 302)
    1368     #     self.failUnlessEqual(Whatsit.objects.count(), 1)
    1369     #     self.failUnlessEqual(Whatsit.objects.all()[0].name, "Whatsit 1")
    1370     #
    1371     #     # Check that the PK link exists on the rendered form
    1372     #     response = self.client.get('/test_admin/admin/admin_views/collector/1/')
    1373     #     self.assertContains(response, 'name="whatsit_set-0-index"')
    1374     #
    1375     #     # Now resave that inline
    1376     #     self.post_data['whatsit_set-INITIAL_FORMS'] = "1"
    1377     #     self.post_data['whatsit_set-0-index'] = "42"
    1378     #     self.post_data['whatsit_set-0-name'] = "Whatsit 1"
    1379     #     response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
    1380     #     self.failUnlessEqual(response.status_code, 302)
    1381     #     self.failUnlessEqual(Whatsit.objects.count(), 1)
    1382     #     self.failUnlessEqual(Whatsit.objects.all()[0].name, "Whatsit 1")
    1383     #
    1384     #     # Now modify that inline
    1385     #     self.post_data['whatsit_set-INITIAL_FORMS'] = "1"
    1386     #     self.post_data['whatsit_set-0-index'] = "42"
    1387     #     self.post_data['whatsit_set-0-name'] = "Whatsit 1 Updated"
    1388     #     response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
    1389     #     self.failUnlessEqual(response.status_code, 302)
    1390     #     self.failUnlessEqual(Whatsit.objects.count(), 1)
    1391     #     self.failUnlessEqual(Whatsit.objects.all()[0].name, "Whatsit 1 Updated")
    1392 
    13931393    def test_inherited_inline(self):
    13941394        "An inherited model can be saved as inlines. Regression for #11042"
    13951395        # First add a new inline
Back to Top