Fixed #12778 - Added media handling abilities to admin inlines. Thanks for the patch, pmclanahan.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12825 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2010-03-21 01:54:00 +00:00
parent 2403f581b3
commit 3f4fef432b
3 changed files with 77 additions and 3 deletions

View File

@ -58,6 +58,7 @@ csrf_protect_m = method_decorator(csrf_protect)
class BaseModelAdmin(object): class BaseModelAdmin(object):
"""Functionality common to both ModelAdmin and InlineAdmin.""" """Functionality common to both ModelAdmin and InlineAdmin."""
__metaclass__ = forms.MediaDefiningClass
raw_id_fields = () raw_id_fields = ()
fields = None fields = None
@ -186,7 +187,6 @@ class BaseModelAdmin(object):
class ModelAdmin(BaseModelAdmin): class ModelAdmin(BaseModelAdmin):
"Encapsulates all admin options and functionality for a given model." "Encapsulates all admin options and functionality for a given model."
__metaclass__ = forms.MediaDefiningClass
list_display = ('__str__',) list_display = ('__str__',)
list_display_links = () list_display_links = ()

View File

@ -45,8 +45,46 @@ class InnerInline(admin.StackedInline):
can_delete = False can_delete = False
# Test bug #12561 class Holder2(models.Model):
admin.site.register(Holder, inlines=[InnerInline]) dummy = models.IntegerField()
class Inner2(models.Model):
dummy = models.IntegerField()
holder = models.ForeignKey(Holder2)
class HolderAdmin(admin.ModelAdmin):
class Media:
js = ('my_awesome_admin_scripts.js',)
class InnerInline2(admin.StackedInline):
model = Inner2
class Media:
js = ('my_awesome_inline_scripts.js',)
class Holder3(models.Model):
dummy = models.IntegerField()
class Inner3(models.Model):
dummy = models.IntegerField()
holder = models.ForeignKey(Holder3)
class InnerInline3(admin.StackedInline):
model = Inner3
class Media:
js = ('my_awesome_inline_scripts.js',)
# Test bug #12561 and #12778
# only ModelAdmin media
admin.site.register(Holder, HolderAdmin, inlines=[InnerInline])
# ModelAdmin and Inline media
admin.site.register(Holder2, HolderAdmin, inlines=[InnerInline2])
# only Inline media
admin.site.register(Holder3, inlines=[InnerInline3])
__test__ = {'API_TESTS': """ __test__ = {'API_TESTS': """

View File

@ -2,6 +2,7 @@ from django.test import TestCase
# local test models # local test models
from models import Holder, Inner, InnerInline from models import Holder, Inner, InnerInline
from models import Holder2, Inner2, Holder3, Inner3
class TestInline(TestCase): class TestInline(TestCase):
fixtures = ['admin-views-users.xml'] fixtures = ['admin-views-users.xml']
@ -28,3 +29,38 @@ class TestInline(TestCase):
actual = inner_formset.can_delete actual = inner_formset.can_delete
self.assertEqual(expected, actual, 'can_delete must be equal') self.assertEqual(expected, actual, 'can_delete must be equal')
class TestInlineMedia(TestCase):
fixtures = ['admin-views-users.xml']
def setUp(self):
result = self.client.login(username='super', password='secret')
self.failUnlessEqual(result, True)
def tearDown(self):
self.client.logout()
def test_inline_media_only_base(self):
holder = Holder(dummy=13)
holder.save()
Inner(dummy=42, holder=holder).save()
change_url = '/test_admin/admin/admin_inlines/holder/%i/' % holder.id
response = self.client.get(change_url)
self.assertContains(response, 'my_awesome_admin_scripts.js')
def test_inline_media_only_inline(self):
holder = Holder3(dummy=13)
holder.save()
Inner3(dummy=42, holder=holder).save()
change_url = '/test_admin/admin/admin_inlines/holder3/%i/' % holder.id
response = self.client.get(change_url)
self.assertContains(response, 'my_awesome_inline_scripts.js')
def test_all_inline_media(self):
holder = Holder2(dummy=13)
holder.save()
Inner2(dummy=42, holder=holder).save()
change_url = '/test_admin/admin/admin_inlines/holder2/%i/' % holder.id
response = self.client.get(change_url)
self.assertContains(response, 'my_awesome_admin_scripts.js')
self.assertContains(response, 'my_awesome_inline_scripts.js')