Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.0.X] Fixed #7510: the ModelAdmin now uses `self.queryset` instead …

…of the default manager. Thanks, Alex Gaynor. Backport of r10314 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10320 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 906f55bf0975e6aa4eb63f4ca71e54baff200bf8 1 parent 53d5f27
@jacobian jacobian authored
View
4 django/contrib/admin/options.py
@@ -556,7 +556,7 @@ def change_view(self, request, object_id, extra_context=None):
opts = model._meta
try:
- obj = model._default_manager.get(pk=object_id)
+ obj = self.queryset(request).get(pk=object_id)
except model.DoesNotExist:
# Don't raise Http404 just yet, because we haven't checked
# permissions yet. We don't want an unauthenticated user to be able
@@ -680,7 +680,7 @@ def delete_view(self, request, object_id, extra_context=None):
app_label = opts.app_label
try:
- obj = self.model._default_manager.get(pk=object_id)
+ obj = self.queryset(request).get(pk=object_id)
except self.model.DoesNotExist:
# Don't raise Http404 just yet, because we haven't checked
# permissions yet. We don't want an unauthenticated user to be able
View
9 tests/regressiontests/admin_views/models.py
@@ -191,6 +191,14 @@ class ParentAdmin(admin.ModelAdmin):
model = Parent
inlines = [ChildInline]
+class EmptyModel(models.Model):
+ def __unicode__(self):
+ return "Primary key = %s" % self.id
+
+class EmptyModelAdmin(admin.ModelAdmin):
+ def queryset(self, request):
+ return super(EmptyModelAdmin, self).queryset(request).filter(pk__gt=1)
+
admin.site.register(Article, ArticleAdmin)
admin.site.register(CustomArticle, CustomArticleAdmin)
admin.site.register(Section, inlines=[ArticleInline])
@@ -199,6 +207,7 @@ class ParentAdmin(admin.ModelAdmin):
admin.site.register(Thing, ThingAdmin)
admin.site.register(Persona, PersonaAdmin)
admin.site.register(Parent, ParentAdmin)
+admin.site.register(EmptyModel, EmptyModelAdmin)
# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
# That way we cover all four cases:
View
26 tests/regressiontests/admin_views/tests.py
@@ -11,7 +11,7 @@
from django.utils.html import escape
# local test models
-from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Persona, FooAccount, BarAccount
+from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Persona, FooAccount, BarAccount, EmptyModel
try:
set
@@ -836,3 +836,27 @@ def test(self):
"""
response = self.client.get('/test_admin/admin/admin_views/parent/add/')
self.failUnlessEqual(response.status_code, 200)
+
+
+class AdminCustomQuerysetTest(TestCase):
+ fixtures = ['admin-views-users.xml']
+
+ def setUp(self):
+ self.client.login(username='super', password='secret')
+ self.pks = [EmptyModel.objects.create().id for i in range(3)]
+
+ def test_changelist_view(self):
+ response = self.client.get('/test_admin/admin/admin_views/emptymodel/')
+ for i in self.pks:
+ if i > 1:
+ self.assertContains(response, 'Primary key = %s' % i)
+ else:
+ self.assertNotContains(response, 'Primary key = %s' % i)
+
+ def test_change_view(self):
+ for i in self.pks:
+ response = self.client.get('/test_admin/admin/admin_views/emptymodel/%s/' % i)
+ if i > 1:
+ self.assertEqual(response.status_code, 200)
+ else:
+ self.assertEqual(response.status_code, 404)
Please sign in to comment.
Something went wrong with that request. Please try again.