mirror of https://github.com/django/django.git
Fixed #21013 -- Ensure that ModelAdmin.get_queryset is considered for the admin history view.
This commit is contained in:
parent
e192739b3e
commit
04415bf81b
1
AUTHORS
1
AUTHORS
|
@ -144,6 +144,7 @@ answer newbie questions, and generally made Django that much better:
|
|||
Ricardo Javier Cárdenes Medina <ricardo.cardenes@gmail.com>
|
||||
Jeremy Carbaugh <jcarbaugh@gmail.com>
|
||||
Graham Carlyle <graham.carlyle@maplecroft.net>
|
||||
Juan Catalano <catalanojuan@gmail.com>
|
||||
Antonio Cavedoni <http://cavedoni.com/>
|
||||
cedric@terramater.net
|
||||
Chris Chamberlin <dja@cdc.msbx.net>
|
||||
|
|
|
@ -1537,7 +1537,7 @@ class ModelAdmin(BaseModelAdmin):
|
|||
from django.contrib.admin.models import LogEntry
|
||||
# First check if the user can see this history.
|
||||
model = self.model
|
||||
obj = get_object_or_404(model, pk=unquote(object_id))
|
||||
obj = get_object_or_404(self.get_queryset(request), pk=unquote(object_id))
|
||||
|
||||
if not self.has_change_permission(request, obj):
|
||||
raise PermissionDenied
|
||||
|
|
|
@ -30,7 +30,7 @@ from .models import (Article, Chapter, Account, Media, Child, Parent, Picture,
|
|||
AdminOrderedField, AdminOrderedModelMethod, AdminOrderedAdminMethod,
|
||||
AdminOrderedCallable, Report, Color2, UnorderedObject, MainPrepopulated,
|
||||
RelatedPrepopulated, UndeletableObject, UnchangeableObject, UserMessenger, Simple, Choice,
|
||||
ShortMessage, Telegram)
|
||||
ShortMessage, Telegram, FilteredManager)
|
||||
|
||||
|
||||
def callable_year(dt_value):
|
||||
|
@ -674,6 +674,12 @@ def callable_on_unknown(obj):
|
|||
class AttributeErrorRaisingAdmin(admin.ModelAdmin):
|
||||
list_display = [callable_on_unknown, ]
|
||||
|
||||
|
||||
class CustomManagerAdmin(admin.ModelAdmin):
|
||||
def get_queryset(self, request):
|
||||
return FilteredManager.objects
|
||||
|
||||
|
||||
class MessageTestingAdmin(admin.ModelAdmin):
|
||||
actions = ["message_debug", "message_info", "message_success",
|
||||
"message_warning", "message_error", "message_extra_tags"]
|
||||
|
@ -773,6 +779,7 @@ site.register(Question)
|
|||
site.register(Answer)
|
||||
site.register(PrePopulatedPost, PrePopulatedPostAdmin)
|
||||
site.register(ComplexSortedPerson, ComplexSortedPersonAdmin)
|
||||
site.register(FilteredManager, CustomManagerAdmin)
|
||||
site.register(PluggableSearchPerson, PluggableSearchPersonAdmin)
|
||||
site.register(PrePopulatedPostLargeSlug, PrePopulatedPostLargeSlugAdmin)
|
||||
site.register(AdminOrderedField, AdminOrderedFieldAdmin)
|
||||
|
|
|
@ -693,3 +693,14 @@ class Simple(models.Model):
|
|||
class Choice(models.Model):
|
||||
choice = models.IntegerField(blank=True, null=True,
|
||||
choices=((1, 'Yes'), (0, 'No'), (None, 'No opinion')))
|
||||
|
||||
class _Manager(models.Manager):
|
||||
def get_queryset(self):
|
||||
return super(_Manager, self).get_queryset().filter(pk__gt=1)
|
||||
|
||||
class FilteredManager(models.Model):
|
||||
def __str__(self):
|
||||
return "PK=%d" % self.pk
|
||||
|
||||
pk_gt_1 = _Manager()
|
||||
objects = models.Manager()
|
||||
|
|
|
@ -48,7 +48,7 @@ from .models import (Article, BarAccount, CustomArticle, EmptyModel, FooAccount,
|
|||
AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable,
|
||||
Report, MainPrepopulated, RelatedPrepopulated, UnorderedObject,
|
||||
Simple, UndeletableObject, UnchangeableObject, Choice, ShortMessage,
|
||||
Telegram, Pizza, Topping)
|
||||
Telegram, Pizza, Topping, FilteredManager)
|
||||
from .admin import site, site2
|
||||
|
||||
|
||||
|
@ -2656,6 +2656,12 @@ class AdminCustomQuerysetTest(TestCase):
|
|||
def setUp(self):
|
||||
self.client.login(username='super', password='secret')
|
||||
self.pks = [EmptyModel.objects.create().id for i in range(3)]
|
||||
self.super_login = {
|
||||
REDIRECT_FIELD_NAME: '/test_admin/admin/',
|
||||
LOGIN_FORM_KEY: 1,
|
||||
'username': 'super',
|
||||
'password': 'secret',
|
||||
}
|
||||
|
||||
def test_changelist_view(self):
|
||||
response = self.client.get('/test_admin/admin/admin_views/emptymodel/')
|
||||
|
@ -2873,6 +2879,20 @@ class AdminCustomQuerysetTest(TestCase):
|
|||
html=True
|
||||
)
|
||||
|
||||
def test_history_view_custom_qs(self):
|
||||
"""
|
||||
Ensure that custom querysets are considered for the admin history view.
|
||||
Refs #21013.
|
||||
"""
|
||||
self.client.post('/test_admin/admin/', self.super_login)
|
||||
FilteredManager.objects.create(pk=1)
|
||||
FilteredManager.objects.create(pk=2)
|
||||
response = self.client.get('/test_admin/admin/admin_views/filteredmanager/')
|
||||
self.assertContains(response, "PK=1")
|
||||
self.assertContains(response, "PK=2")
|
||||
self.assertEqual(self.client.get('/test_admin/admin/admin_views/filteredmanager/1/history/').status_code, 200)
|
||||
self.assertEqual(self.client.get('/test_admin/admin/admin_views/filteredmanager/2/history/').status_code, 200)
|
||||
|
||||
|
||||
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||
class AdminInlineFileUploadTest(TestCase):
|
||||
|
|
Loading…
Reference in New Issue