diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 501014a..41b0412 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
523 | 523 | app_label = opts.app_label |
524 | 524 | |
525 | 525 | try: |
526 | | obj = model._default_manager.get(pk=object_id) |
| 526 | obj = self.queryset(request).get(pk=object_id) |
527 | 527 | except model.DoesNotExist: |
528 | 528 | # Don't raise Http404 just yet, because we haven't checked |
529 | 529 | # permissions yet. We don't want an unauthenticated user to be able |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
621 | 621 | app_label = opts.app_label |
622 | 622 | |
623 | 623 | try: |
624 | | obj = self.model._default_manager.get(pk=object_id) |
| 624 | obj = self.queryset(request).get(pk=object_id) |
625 | 625 | except self.model.DoesNotExist: |
626 | 626 | # Don't raise Http404 just yet, because we haven't checked |
627 | 627 | # 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 2062107..b533f00 100644
a
|
b
|
class CustomArticle(models.Model):
|
32 | 32 | content = models.TextField() |
33 | 33 | date = models.DateTimeField() |
34 | 34 | |
| 35 | class EmptyModel(models.Model): |
| 36 | def __unicode__(self): |
| 37 | return "Primary key = %s" % self.id |
| 38 | |
| 39 | class EmptyModelAdmin(admin.ModelAdmin): |
| 40 | def queryset(self, request): |
| 41 | return super(EmptyModelAdmin, self).queryset(request).filter(pk__gt=1) |
| 42 | |
35 | 43 | class CustomArticleAdmin(admin.ModelAdmin): |
36 | 44 | """ |
37 | 45 | Tests various hooks for using custom templates and contexts. |
… |
… |
class ModelWithStringPrimaryKey(models.Model):
|
58 | 66 | admin.site.register(Article, ArticleAdmin) |
59 | 67 | admin.site.register(CustomArticle, CustomArticleAdmin) |
60 | 68 | admin.site.register(Section) |
| 69 | admin.site.register(EmptyModel, EmptyModelAdmin) |
61 | 70 | admin.site.register(ModelWithStringPrimaryKey) |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index ad50928..ed9447a 100644
a
|
b
|
from django.contrib.admin.util import quote
|
8 | 8 | from django.utils.html import escape |
9 | 9 | |
10 | 10 | # local test models |
11 | | from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey |
| 11 | from models import Article, CustomArticle, Section, EmptyModel, ModelWithStringPrimaryKey |
12 | 12 | |
13 | 13 | def get_perm(Model, perm): |
14 | 14 | """Return the permission object, for the Model""" |
… |
… |
class AdminViewStringPrimaryKeyTest(TestCase):
|
360 | 360 | response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/delete/' % quote(self.pk)) |
361 | 361 | should_contain = """<a href="../../%s/">%s</a>""" % (quote(self.pk), escape(self.pk)) |
362 | 362 | self.assertContains(response, should_contain) |
| 363 | |
| 364 | class AdminCustomQuerytetTest(TestCase): |
| 365 | fixtures = ['admin-views-users.xml'] |
| 366 | |
| 367 | def setUp(self): |
| 368 | self.client.login(username='super', password='secret') |
| 369 | self.pks = [] |
| 370 | self.pks.append(EmptyModel.objects.create().id) |
| 371 | self.pks.append(EmptyModel.objects.create().id) |
| 372 | self.pks.append(EmptyModel.objects.create().id) |
| 373 | |
| 374 | def test_changelist_view(self): |
| 375 | response = self.client.get('/test_admin/admin/admin_views/emptymodel/') |
| 376 | for i in self.pks: |
| 377 | if i > 1: |
| 378 | self.assertContains(response, 'Primary key = %s' % i) |
| 379 | else: |
| 380 | self.assertNotContains(response, 'Primary key = %s' % i) |
| 381 | |
| 382 | def test_change_view(self): |
| 383 | for i in self.pks: |
| 384 | response = self.client.get('/test_admin/admin/admin_views/emptymodel/%s/' % i) |
| 385 | if i > 1: |
| 386 | self.assertEqual(response.status_code, 200) |
| 387 | else: |
| 388 | self.assertEqual(response.status_code, 404) |
| 389 | |
| 390 | |
| 391 | |