summaryrefslogtreecommitdiff
path: root/tests/admin_views
diff options
context:
space:
mode:
authorVasilis Aggelou <dimitrovasilis@hotmail.com>2017-09-04 12:24:34 +0300
committerTim Graham <timograham@gmail.com>2018-01-05 18:28:45 -0500
commit777f216d555496798a1e65fd899b0f8a0349aeca (patch)
treec7019a417caf39f4d7a9acfd6b7629029befa3cc /tests/admin_views
parentec2ce4517ac89f6c6334fe5322d1fc2007dfcbd4 (diff)
Fixed #15522 -- Added ModelAdmin.delete_queryset() to customize "delete selected objects" deletion.
Diffstat (limited to 'tests/admin_views')
-rw-r--r--tests/admin_views/admin.py4
-rw-r--r--tests/admin_views/test_actions.py14
2 files changed, 18 insertions, 0 deletions
diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py
index 12087865b4..3cfefb74e4 100644
--- a/tests/admin_views/admin.py
+++ b/tests/admin_views/admin.py
@@ -232,6 +232,10 @@ class SubscriberAdmin(admin.ModelAdmin):
actions = ['mail_admin']
action_form = MediaActionForm
+ def delete_queryset(self, request, queryset):
+ SubscriberAdmin.overridden = True
+ super().delete_queryset(request, queryset)
+
def mail_admin(self, request, selected):
EmailMessage(
'Greetings from a ModelAdmin action',
diff --git a/tests/admin_views/test_actions.py b/tests/admin_views/test_actions.py
index 453de691ce..b77714b32d 100644
--- a/tests/admin_views/test_actions.py
+++ b/tests/admin_views/test_actions.py
@@ -9,6 +9,7 @@ from django.template.response import TemplateResponse
from django.test import TestCase, override_settings
from django.urls import reverse
+from .admin import SubscriberAdmin
from .forms import MediaActionForm
from .models import (
Actor, Answer, ExternalSubscriber, Question, Subscriber,
@@ -128,6 +129,19 @@ class AdminActionsTest(TestCase):
# The page doesn't display a link to the nonexistent change page.
self.assertContains(response, '<li>Unchangeable object: %s</li>' % obj, 1, html=True)
+ def test_delete_queryset_hook(self):
+ delete_confirmation_data = {
+ ACTION_CHECKBOX_NAME: [self.s1.pk, self.s2.pk],
+ 'action': 'delete_selected',
+ 'post': 'yes',
+ 'index': 0,
+ }
+ SubscriberAdmin.overridden = False
+ self.client.post(reverse('admin:admin_views_subscriber_changelist'), delete_confirmation_data)
+ # SubscriberAdmin.delete_queryset() sets overridden to True.
+ self.assertIs(SubscriberAdmin.overridden, True)
+ self.assertEqual(Subscriber.objects.all().count(), 0)
+
def test_custom_function_mail_action(self):
"""A custom action may be defined in a function."""
action_data = {