mirror of https://github.com/django/django.git
Fixed #7510: the ModelAdmin now uses `self.queryset` instead of the default manager. Thanks, Alex Gaynor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10314 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
1f74e3382f
commit
f83af07ce3
|
@ -791,7 +791,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||||
opts = model._meta
|
opts = model._meta
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj = model._default_manager.get(pk=unquote(object_id))
|
obj = self.queryset(request).get(pk=unquote(object_id))
|
||||||
except model.DoesNotExist:
|
except model.DoesNotExist:
|
||||||
# Don't raise Http404 just yet, because we haven't checked
|
# Don't raise Http404 just yet, because we haven't checked
|
||||||
# permissions yet. We don't want an unauthenticated user to be able
|
# permissions yet. We don't want an unauthenticated user to be able
|
||||||
|
@ -976,7 +976,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||||
app_label = opts.app_label
|
app_label = opts.app_label
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj = self.model._default_manager.get(pk=unquote(object_id))
|
obj = self.queryset(request).get(pk=unquote(object_id))
|
||||||
except self.model.DoesNotExist:
|
except self.model.DoesNotExist:
|
||||||
# Don't raise Http404 just yet, because we haven't checked
|
# Don't raise Http404 just yet, because we haven't checked
|
||||||
# permissions yet. We don't want an unauthenticated user to be able
|
# permissions yet. We don't want an unauthenticated user to be able
|
||||||
|
|
|
@ -262,6 +262,14 @@ class ParentAdmin(admin.ModelAdmin):
|
||||||
model = Parent
|
model = Parent
|
||||||
inlines = [ChildInline]
|
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(Article, ArticleAdmin)
|
||||||
admin.site.register(CustomArticle, CustomArticleAdmin)
|
admin.site.register(CustomArticle, CustomArticleAdmin)
|
||||||
admin.site.register(Section, inlines=[ArticleInline])
|
admin.site.register(Section, inlines=[ArticleInline])
|
||||||
|
@ -274,6 +282,7 @@ admin.site.register(Subscriber, SubscriberAdmin)
|
||||||
admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin)
|
admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin)
|
||||||
admin.site.register(Podcast, PodcastAdmin)
|
admin.site.register(Podcast, PodcastAdmin)
|
||||||
admin.site.register(Parent, ParentAdmin)
|
admin.site.register(Parent, ParentAdmin)
|
||||||
|
admin.site.register(EmptyModel, EmptyModelAdmin)
|
||||||
|
|
||||||
# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
|
# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
|
||||||
# That way we cover all four cases:
|
# That way we cover all four cases:
|
||||||
|
|
|
@ -13,7 +13,7 @@ from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
|
|
||||||
# local test models
|
# local test models
|
||||||
from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber, Podcast
|
from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber, Podcast, EmptyModel
|
||||||
|
|
||||||
try:
|
try:
|
||||||
set
|
set
|
||||||
|
@ -963,3 +963,27 @@ class TestInlineNotEditable(TestCase):
|
||||||
"""
|
"""
|
||||||
response = self.client.get('/test_admin/admin/admin_views/parent/add/')
|
response = self.client.get('/test_admin/admin/admin_views/parent/add/')
|
||||||
self.failUnlessEqual(response.status_code, 200)
|
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)
|
||||||
|
|
Loading…
Reference in New Issue