mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #16101 -- Added parameters to SingleObjectMixin to override the name of the URL keyword arguments used for pk and slug. Thanks, Andrew Ingram and Julien Phalip.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16569 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -21,6 +21,13 @@ class DetailViewTest(TestCase):
|
||||
self.assertEqual(res.context['author'], Author.objects.get(pk=1))
|
||||
self.assertTemplateUsed(res, 'generic_views/author_detail.html')
|
||||
|
||||
def test_detail_by_custom_pk(self):
|
||||
res = self.client.get('/detail/author/bycustompk/1/')
|
||||
self.assertEqual(res.status_code, 200)
|
||||
self.assertEqual(res.context['object'], Author.objects.get(pk=1))
|
||||
self.assertEqual(res.context['author'], Author.objects.get(pk=1))
|
||||
self.assertTemplateUsed(res, 'generic_views/author_detail.html')
|
||||
|
||||
def test_detail_by_slug(self):
|
||||
res = self.client.get('/detail/author/byslug/scott-rosenberg/')
|
||||
self.assertEqual(res.status_code, 200)
|
||||
@@ -28,6 +35,13 @@ class DetailViewTest(TestCase):
|
||||
self.assertEqual(res.context['author'], Author.objects.get(slug='scott-rosenberg'))
|
||||
self.assertTemplateUsed(res, 'generic_views/author_detail.html')
|
||||
|
||||
def test_detail_by_custom_slug(self):
|
||||
res = self.client.get('/detail/author/bycustomslug/scott-rosenberg/')
|
||||
self.assertEqual(res.status_code, 200)
|
||||
self.assertEqual(res.context['object'], Author.objects.get(slug='scott-rosenberg'))
|
||||
self.assertEqual(res.context['author'], Author.objects.get(slug='scott-rosenberg'))
|
||||
self.assertTemplateUsed(res, 'generic_views/author_detail.html')
|
||||
|
||||
def test_verbose_name(self):
|
||||
res = self.client.get('/detail/artist/1/')
|
||||
self.assertEqual(res.status_code, 200)
|
||||
|
||||
@@ -30,8 +30,12 @@ urlpatterns = patterns('',
|
||||
url(r'^detail/author/(?P<pk>\d+)/$',
|
||||
views.AuthorDetail.as_view(),
|
||||
name="author_detail"),
|
||||
(r'^detail/author/bycustompk/(?P<foo>\d+)/$',
|
||||
views.AuthorDetail.as_view(pk_url_kwarg='foo')),
|
||||
(r'^detail/author/byslug/(?P<slug>[\w-]+)/$',
|
||||
views.AuthorDetail.as_view()),
|
||||
(r'^detail/author/bycustomslug/(?P<foo>[\w-]+)/$',
|
||||
views.AuthorDetail.as_view(slug_url_kwarg='foo')),
|
||||
(r'^detail/author/(?P<pk>\d+)/template_name_suffix/$',
|
||||
views.AuthorDetail.as_view(template_name_suffix='_view')),
|
||||
(r'^detail/author/(?P<pk>\d+)/template_name/$',
|
||||
|
||||
Reference in New Issue
Block a user