From 30cacb75693a4ffe464ddfa85832b462f3fa9a2e Mon Sep 17 00:00:00 2001 From: Ben Tappin Date: Fri, 24 May 2013 12:06:35 +0100 Subject: [PATCH] Use PK instead of ID in the model list view and template. --- .../admin2/bootstrap/delete_selected_confirmation.html | 2 +- djadmin2/templates/admin2/bootstrap/model_list.html | 2 +- djadmin2/views.py | 4 ++-- example/blog/tests/test_views.py | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/djadmin2/templates/admin2/bootstrap/delete_selected_confirmation.html b/djadmin2/templates/admin2/bootstrap/delete_selected_confirmation.html index 72f1452..111d8c2 100644 --- a/djadmin2/templates/admin2/bootstrap/delete_selected_confirmation.html +++ b/djadmin2/templates/admin2/bootstrap/delete_selected_confirmation.html @@ -15,7 +15,7 @@ {% for item in queryset %} - + {% endfor %} diff --git a/djadmin2/templates/admin2/bootstrap/model_list.html b/djadmin2/templates/admin2/bootstrap/model_list.html index 1f4ca99..d8bb933 100644 --- a/djadmin2/templates/admin2/bootstrap/model_list.html +++ b/djadmin2/templates/admin2/bootstrap/model_list.html @@ -38,7 +38,7 @@ {% for obj in object_list %} - + {{ obj }} detail {# if has_edit_permission #} diff --git a/djadmin2/views.py b/djadmin2/views.py index 3e3ea73..724bb05 100644 --- a/djadmin2/views.py +++ b/djadmin2/views.py @@ -29,8 +29,8 @@ class ModelListView(Admin2Mixin, generic.ListView): # This is where we handle actions action_name = request.POST['action'] action_func = self.get_actions()[action_name]['func'] - selected_model_ids = request.POST.getlist('selected_model_id') - queryset = self.model.objects.filter(pk__in=selected_model_ids) + selected_model_pks = request.POST.getlist('selected_model_pk') + queryset = self.model.objects.filter(pk__in=selected_model_pks) response = action_func(request, queryset) if response is None: return HttpResponseRedirect(self.get_success_url()) diff --git a/example/blog/tests/test_views.py b/example/blog/tests/test_views.py index e378e6e..0599ca1 100644 --- a/example/blog/tests/test_views.py +++ b/example/blog/tests/test_views.py @@ -36,13 +36,13 @@ class PostListTest(BaseIntegrationTest): def test_delete_selected_post(self): post = Post.objects.create(title="a_post_title", body="body") - params = {'action': 'delete_selected', 'selected_model_id': str(post.id)} + params = {'action': 'delete_selected', 'selected_model_pk': str(post.pk)} response = self.client.post(reverse("admin2:blog_post_index"), params) self.assertInHTML('

Are you sure you want to delete the selected post?

', response.content) def test_delete_selected_post_confirmation(self): post = Post.objects.create(title="a_post_title", body="body") - params = {'action': 'delete_selected', 'selected_model_id': str(post.id), 'confirmed': 'yes'} + params = {'action': 'delete_selected', 'selected_model_pk': str(post.pk), 'confirmed': 'yes'} response = self.client.post(reverse("admin2:blog_post_index"), params) self.assertRedirects(response, reverse("admin2:blog_post_index")) @@ -141,7 +141,7 @@ class PostDeleteActionTest(BaseIntegrationTest): p2 = Post.objects.create(title="A Post Title", body="body") post_data = { 'action': 'delete_selected', - 'selected_model_id': [p1.id, p2.id] + 'selected_model_pk': [p1.pk, p2.pk] } response = self.client.post(reverse("admin2:blog_post_index"), post_data) @@ -153,7 +153,7 @@ class PostDeleteActionTest(BaseIntegrationTest): p2 = Post.objects.create(title="A Post Title", body="body") post_data = { 'action': 'delete_selected', - 'selected_model_id': [p1.id, p2.id], + 'selected_model_pk': [p1.pk, p2.pk], 'confirmed': 'yes' } response = self.client.post(reverse("admin2:blog_post_index"),