diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html index 79c4f1bdf4..ead37b187f 100644 --- a/django/contrib/admin/templates/admin/change_form.html +++ b/django/contrib/admin/templates/admin/change_form.html @@ -31,7 +31,7 @@ {% endif %}{% endif %} diff --git a/tests/regressiontests/admin_views/fixtures/string-primary-key.xml b/tests/regressiontests/admin_views/fixtures/string-primary-key.xml index 8e1dbf047f..1792cb2d7e 100644 --- a/tests/regressiontests/admin_views/fixtures/string-primary-key.xml +++ b/tests/regressiontests/admin_views/fixtures/string-primary-key.xml @@ -1,6 +1,6 @@ - #%" {}|\^[]`]]> - - \ No newline at end of file + #%" {}|\^[]`]]> + + diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index 17533f9f80..2da86e2099 100644 --- a/tests/regressiontests/admin_views/models.py +++ b/tests/regressiontests/admin_views/models.py @@ -93,10 +93,13 @@ class CustomArticle(models.Model): class ModelWithStringPrimaryKey(models.Model): - id = models.CharField(max_length=255, primary_key=True) + string_pk = models.CharField(max_length=255, primary_key=True) def __unicode__(self): - return self.id + return self.string_pk + + def get_absolute_url(self): + return u'/dummy/%s/' % self.string_pk class Color(models.Model): diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index f9a9b15114..e8d05f78ff 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -1403,7 +1403,7 @@ class AdminViewStringPrimaryKeyTest(TestCase): def test_url_conflicts_with_add(self): "A model with a primary key that ends with add should be visible" - add_model = ModelWithStringPrimaryKey(id="i have something to add") + add_model = ModelWithStringPrimaryKey(pk="i have something to add") add_model.save() response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(add_model.pk)) should_contain = """

Change model with string primary key

""" @@ -1411,7 +1411,7 @@ class AdminViewStringPrimaryKeyTest(TestCase): def test_url_conflicts_with_delete(self): "A model with a primary key that ends with delete should be visible" - delete_model = ModelWithStringPrimaryKey(id="delete") + delete_model = ModelWithStringPrimaryKey(pk="delete") delete_model.save() response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(delete_model.pk)) should_contain = """

Change model with string primary key

""" @@ -1419,12 +1419,20 @@ class AdminViewStringPrimaryKeyTest(TestCase): def test_url_conflicts_with_history(self): "A model with a primary key that ends with history should be visible" - history_model = ModelWithStringPrimaryKey(id="history") + history_model = ModelWithStringPrimaryKey(pk="history") history_model.save() response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(history_model.pk)) should_contain = """

Change model with string primary key

""" self.assertContains(response, should_contain) + def test_shortcut_view_with_escaping(self): + "'View on site should' work properly with char fields" + model = ModelWithStringPrimaryKey(pk='abc_123') + model.save() + response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(model.pk)) + should_contain = '/%s/" class="viewsitelink">' % model.pk + self.assertContains(response, should_contain) + @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) class SecureViewTests(TestCase):