diff --git a/tests/admin_changelist/admin.py b/tests/admin_changelist/admin.py
index 34e84a06b6..97833fa86b 100644
a
|
b
|
from django.contrib.auth.admin import UserAdmin
|
3 | 3 | from django.contrib.auth.models import User |
4 | 4 | from django.core.paginator import Paginator |
5 | 5 | |
6 | | from .models import Band, Child, Event, Parent, Swallow |
| 6 | from .models import Band, Child, Event, Parent, SoftDeletable, Swallow |
7 | 7 | |
8 | 8 | site = admin.AdminSite(name="admin") |
9 | 9 | |
… |
… |
class EmptyValueChildAdmin(admin.ModelAdmin):
|
176 | 176 | @admin.display(empty_value='†') |
177 | 177 | def age_display(self, obj): |
178 | 178 | return obj.age |
| 179 | |
| 180 | |
| 181 | class SoftDeletableAdmin(admin.ModelAdmin): |
| 182 | list_display = ["name", "deleted"] |
| 183 | list_editable = ["deleted"] |
| 184 | ordering = ["name"] |
| 185 | |
| 186 | def get_queryset(self, request): |
| 187 | return self.model.include_deleted.all() |
| 188 | |
| 189 | |
| 190 | site.register(SoftDeletable, SoftDeletableAdmin) |
diff --git a/tests/admin_changelist/models.py b/tests/admin_changelist/models.py
index 81d7fdfb3a..0e6387d0a1 100644
a
|
b
|
class CustomIdUser(models.Model):
|
119 | 119 | |
120 | 120 | class CharPK(models.Model): |
121 | 121 | char_pk = models.CharField(max_length=100, primary_key=True) |
| 122 | |
| 123 | |
| 124 | class SoftDeletableManager(models.Manager): |
| 125 | def get_queryset(self): |
| 126 | return super().get_queryset().filter(deleted=False) |
| 127 | |
| 128 | |
| 129 | class SoftDeletable(models.Model): |
| 130 | name = models.CharField(max_length=20) |
| 131 | deleted = models.BooleanField(default=False) |
| 132 | |
| 133 | objects = SoftDeletableManager() |
| 134 | include_deleted = models.Manager() |
diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
index 08fe636128..3928d19214 100644
a
|
b
|
from .admin import (
|
36 | 36 | from .models import ( |
37 | 37 | Band, CharPK, Child, ChordsBand, ChordsMusician, Concert, CustomIdUser, |
38 | 38 | Event, Genre, Group, Invitation, Membership, Musician, OrderedObject, |
39 | | Parent, Quartet, Swallow, SwallowOneToOne, UnorderedObject, |
| 39 | Parent, Quartet, SoftDeletable, Swallow, SwallowOneToOne, UnorderedObject, |
40 | 40 | ) |
41 | 41 | |
42 | 42 | |
… |
… |
class ChangeListTests(TestCase):
|
272 | 272 | with self.assertRaises(IncorrectLookupParameters): |
273 | 273 | m.get_changelist_instance(request) |
274 | 274 | |
| 275 | def test_list_editable_edit_objects_excluded_by_default_manager(self): |
| 276 | deleted = SoftDeletable.objects.create(name='1-deleted', deleted=True) |
| 277 | active = SoftDeletable.objects.create(name='2-active') |
| 278 | self.client.force_login(self.superuser) |
| 279 | changelist_url = reverse('admin:admin_changelist_softdeletable_changelist') |
| 280 | data = { |
| 281 | "form-INITIAL_FORMS": 2, |
| 282 | "form-TOTAL_FORMS": 2, |
| 283 | "form-0-id": deleted.pk, |
| 284 | # Restore the soft-deleted row. |
| 285 | "form-0-deleted": False, |
| 286 | "form-1-id": active.pk, |
| 287 | "form-1-deleted": False, |
| 288 | "_save": True, |
| 289 | } |
| 290 | response = self.client.post(changelist_url, data) |
| 291 | self.assertEqual(response.status_code, 302) |
| 292 | self.assertQuerysetEqual( |
| 293 | SoftDeletable.include_deleted.values_list("pk", "name", "deleted").order_by("name"), |
| 294 | [ |
| 295 | (deleted.pk, "1-deleted", False), |
| 296 | (active.pk, "2-active", False), |
| 297 | ], |
| 298 | ) |
| 299 | |
275 | 300 | def test_custom_paginator(self): |
276 | 301 | new_parent = Parent.objects.create(name='parent') |
277 | 302 | for i in range(1, 201): |