diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 4504e9dbb3..be91ffa41e 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -58,6 +58,7 @@ csrf_protect_m = method_decorator(csrf_protect) class BaseModelAdmin(object): """Functionality common to both ModelAdmin and InlineAdmin.""" + __metaclass__ = forms.MediaDefiningClass raw_id_fields = () fields = None @@ -186,7 +187,6 @@ class BaseModelAdmin(object): class ModelAdmin(BaseModelAdmin): "Encapsulates all admin options and functionality for a given model." - __metaclass__ = forms.MediaDefiningClass list_display = ('__str__',) list_display_links = () diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py index 303c06a3d9..9b491eb939 100644 --- a/tests/regressiontests/admin_inlines/models.py +++ b/tests/regressiontests/admin_inlines/models.py @@ -45,8 +45,46 @@ class InnerInline(admin.StackedInline): can_delete = False -# Test bug #12561 -admin.site.register(Holder, inlines=[InnerInline]) +class Holder2(models.Model): + 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': """ diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py index 75a6658599..9207c5521c 100644 --- a/tests/regressiontests/admin_inlines/tests.py +++ b/tests/regressiontests/admin_inlines/tests.py @@ -2,6 +2,7 @@ from django.test import TestCase # local test models from models import Holder, Inner, InnerInline +from models import Holder2, Inner2, Holder3, Inner3 class TestInline(TestCase): fixtures = ['admin-views-users.xml'] @@ -28,3 +29,38 @@ class TestInline(TestCase): actual = inner_formset.can_delete 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') \ No newline at end of file