diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 8cc27c5..7cb1aac 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
791 | 791 | opts = model._meta |
792 | 792 | |
793 | 793 | try: |
794 | | obj = model._default_manager.get(pk=unquote(object_id)) |
| 794 | obj = self.queryset(request).get(pk=unquote(object_id)) |
795 | 795 | except model.DoesNotExist: |
796 | 796 | # Don't raise Http404 just yet, because we haven't checked |
797 | 797 | # permissions yet. We don't want an unauthenticated user to be able |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
976 | 976 | app_label = opts.app_label |
977 | 977 | |
978 | 978 | try: |
979 | | obj = self.model._default_manager.get(pk=unquote(object_id)) |
| 979 | obj = self.queryset(request).get(pk=unquote(object_id)) |
980 | 980 | except self.model.DoesNotExist: |
981 | 981 | # Don't raise Http404 just yet, because we haven't checked |
982 | 982 | # permissions yet. We don't want an unauthenticated user to be able |
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
index 8fc3d38..e2d087d 100644
a
|
b
|
class ParentAdmin(admin.ModelAdmin):
|
262 | 262 | model = Parent |
263 | 263 | inlines = [ChildInline] |
264 | 264 | |
| 265 | class EmptyModel(models.Model): |
| 266 | def __unicode__(self): |
| 267 | return "Primary key = %s" % self.id |
| 268 | |
| 269 | class EmptyModelAdmin(admin.ModelAdmin): |
| 270 | def queryset(self, request): |
| 271 | return super(EmptyModelAdmin, self).queryset(request).filter(pk__gt=1) |
| 272 | |
265 | 273 | admin.site.register(Article, ArticleAdmin) |
266 | 274 | admin.site.register(CustomArticle, CustomArticleAdmin) |
267 | 275 | admin.site.register(Section, inlines=[ArticleInline]) |
… |
… |
admin.site.register(Subscriber, SubscriberAdmin)
|
274 | 282 | admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin) |
275 | 283 | admin.site.register(Podcast, PodcastAdmin) |
276 | 284 | admin.site.register(Parent, ParentAdmin) |
| 285 | admin.site.register(EmptyModel, EmptyModelAdmin) |
277 | 286 | |
278 | 287 | # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. |
279 | 288 | # That way we cover all four cases: |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index bba7f6a..447667e 100644
a
|
b
|
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
|
13 | 13 | from django.utils.html import escape |
14 | 14 | |
15 | 15 | # local test models |
16 | | from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber, Podcast |
| 16 | from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber, Podcast, EmptyModel |
17 | 17 | |
18 | 18 | try: |
19 | 19 | set |
… |
… |
class TestInlineNotEditable(TestCase):
|
963 | 963 | """ |
964 | 964 | response = self.client.get('/test_admin/admin/admin_views/parent/add/') |
965 | 965 | self.failUnlessEqual(response.status_code, 200) |
| 966 | |
| 967 | |
| 968 | class AdminCustomQuerysetTest(TestCase): |
| 969 | fixtures = ['admin-views-users.xml'] |
| 970 | |
| 971 | def setUp(self): |
| 972 | self.client.login(username='super', password='secret') |
| 973 | self.pks = [] |
| 974 | self.pks.append(EmptyModel.objects.create().id) |
| 975 | self.pks.append(EmptyModel.objects.create().id) |
| 976 | self.pks.append(EmptyModel.objects.create().id) |
| 977 | |
| 978 | def test_changelist_view(self): |
| 979 | response = self.client.get('/test_admin/admin/admin_views/emptymodel/') |
| 980 | for i in self.pks: |
| 981 | if i > 1: |
| 982 | self.assertContains(response, 'Primary key = %s' % i) |
| 983 | else: |
| 984 | self.assertNotContains(response, 'Primary key = %s' % i) |
| 985 | |
| 986 | def test_change_view(self): |
| 987 | for i in self.pks: |
| 988 | response = self.client.get('/test_admin/admin/admin_views/emptymodel/%s/' % i) |
| 989 | if i > 1: |
| 990 | self.assertEqual(response.status_code, 200) |
| 991 | else: |
| 992 | self.assertEqual(response.status_code, 404) |