diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index d435675..5d9a2f4 100644
a
|
b
|
from django.forms.models import (modelform_factory, modelformset_factory,
|
28 | 28 | inlineformset_factory, BaseInlineFormSet, modelform_defines_fields) |
29 | 29 | from django.http import Http404, HttpResponseRedirect |
30 | 30 | from django.http.response import HttpResponseBase |
31 | | from django.shortcuts import get_object_or_404 |
32 | 31 | from django.template.response import SimpleTemplateResponse, TemplateResponse |
33 | 32 | from django.utils.decorators import method_decorator |
34 | 33 | from django.utils.html import escape, escapejs |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1517 | 1516 | from django.contrib.admin.models import LogEntry |
1518 | 1517 | # First check if the user can see this history. |
1519 | 1518 | model = self.model |
1520 | | obj = get_object_or_404(model, pk=unquote(object_id)) |
| 1519 | obj = self.get_object(request, unquote(object_id)) |
| 1520 | if obj is None: |
| 1521 | raise Http404('No %s matches the given query.' % model._meta.object_name) |
1521 | 1522 | |
1522 | 1523 | if not self.has_change_permission(request, obj): |
1523 | 1524 | raise PermissionDenied |
diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py
index b2da23f..a3ce942 100644
a
|
b
|
from .models import (Article, Chapter, Account, Media, Child, Parent, Picture,
|
29 | 29 | Album, Question, Answer, ComplexSortedPerson, PluggableSearchPerson, PrePopulatedPostLargeSlug, |
30 | 30 | AdminOrderedField, AdminOrderedModelMethod, AdminOrderedAdminMethod, |
31 | 31 | AdminOrderedCallable, Report, Color2, UnorderedObject, MainPrepopulated, |
32 | | RelatedPrepopulated, UndeletableObject, UnchangeableObject, UserMessenger, Simple, Choice, |
33 | | ShortMessage, Telegram) |
| 32 | RelatedPrepopulated, UndeletableObject, UnchangeableObject, UserMessenger, |
| 33 | Simple, FilteredManager, Choice, ShortMessage, Telegram) |
34 | 34 | |
35 | 35 | |
36 | 36 | def callable_year(dt_value): |
… |
… |
def callable_on_unknown(obj):
|
674 | 674 | class AttributeErrorRaisingAdmin(admin.ModelAdmin): |
675 | 675 | list_display = [callable_on_unknown, ] |
676 | 676 | |
| 677 | class CustomManagerAdmin(admin.ModelAdmin): |
| 678 | def get_queryset(self, request): |
| 679 | return FilteredManager.objects |
| 680 | |
677 | 681 | class MessageTestingAdmin(admin.ModelAdmin): |
678 | 682 | actions = ["message_debug", "message_info", "message_success", |
679 | 683 | "message_warning", "message_error", "message_extra_tags"] |
… |
… |
site.register(AdminOrderedAdminMethod, AdminOrderedAdminMethodAdmin)
|
781 | 785 | site.register(AdminOrderedCallable, AdminOrderedCallableAdmin) |
782 | 786 | site.register(Color2, CustomTemplateFilterColorAdmin) |
783 | 787 | site.register(Simple, AttributeErrorRaisingAdmin) |
| 788 | site.register(FilteredManager, CustomManagerAdmin) |
784 | 789 | site.register(UserMessenger, MessageTestingAdmin) |
785 | 790 | site.register(Choice, ChoiceList) |
786 | 791 | |
diff --git a/tests/admin_views/models.py b/tests/admin_views/models.py
index 6483fc8..40336c1 100644
a
|
b
|
class Simple(models.Model):
|
690 | 690 | Simple model with nothing on it for use in testing |
691 | 691 | """ |
692 | 692 | |
| 693 | class _Manager(models.Manager): |
| 694 | def get_queryset(self): |
| 695 | return super(_Manager, self).get_queryset().filter(pk__gt=1) |
| 696 | |
| 697 | class FilteredManager(models.Model): |
| 698 | def __str__(self): |
| 699 | return "PK=%d" % self.pk |
| 700 | |
| 701 | pk_gt_1 = _Manager() |
| 702 | objects = models.Manager() |
| 703 | |
693 | 704 | class Choice(models.Model): |
694 | 705 | choice = models.IntegerField(blank=True, null=True, |
695 | 706 | choices=((1, 'Yes'), (0, 'No'), (None, 'No opinion'))) |
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index aa5f9ec..2873cae 100644
a
|
b
|
from .models import (Article, BarAccount, CustomArticle, EmptyModel, FooAccount,
|
51 | 51 | AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable, |
52 | 52 | Report, MainPrepopulated, RelatedPrepopulated, UnorderedObject, |
53 | 53 | Simple, UndeletableObject, UnchangeableObject, Choice, ShortMessage, |
54 | | Telegram, Pizza, Topping) |
| 54 | Telegram, Pizza, Topping, FilteredManager) |
55 | 55 | from .admin import site, site2 |
56 | 56 | |
57 | 57 | |
… |
… |
class AdminViewPermissionsTest(TestCase):
|
1212 | 1212 | |
1213 | 1213 | self.client.get('/test_admin/admin/logout/') |
1214 | 1214 | |
| 1215 | def testHistoryViewCustomQueryset(self): |
| 1216 | self.client.post('/test_admin/admin/', self.super_login) |
| 1217 | FilteredManager.objects.create(pk=1) |
| 1218 | FilteredManager.objects.create(pk=2) |
| 1219 | response = self.client.get('/test_admin/admin/admin_views/filteredmanager/') |
| 1220 | self.assertContains(response, "PK=1") |
| 1221 | self.assertContains(response, "PK=2") |
| 1222 | self.assertEqual(self.client.get('/test_admin/admin/admin_views/filteredmanager/1/history/').status_code, 200) |
| 1223 | self.assertEqual(self.client.get('/test_admin/admin/admin_views/filteredmanager/2/history/').status_code, 200) |
| 1224 | |
1215 | 1225 | def testConditionallyShowAddSectionLink(self): |
1216 | 1226 | """ |
1217 | 1227 | The foreign key widget should only show the "add related" button if the |