Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #12778 - Added media handling abilities to admin inlines. Thank…

…s for the patch, pmclanahan.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12825 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3f4fef432b10fdf69271ccb57181a43484916c7b 1 parent 2403f58
@jezdez jezdez authored
View
2  django/contrib/admin/options.py
@@ -58,6 +58,7 @@ class IncorrectLookupParameters(Exception):
class BaseModelAdmin(object):
"""Functionality common to both ModelAdmin and InlineAdmin."""
+ __metaclass__ = forms.MediaDefiningClass
raw_id_fields = ()
fields = None
@@ -186,7 +187,6 @@ def get_readonly_fields(self, request, obj=None):
class ModelAdmin(BaseModelAdmin):
"Encapsulates all admin options and functionality for a given model."
- __metaclass__ = forms.MediaDefiningClass
list_display = ('__str__',)
list_display_links = ()
View
42 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': """
View
36 tests/regressiontests/admin_inlines/tests.py
@@ -2,6 +2,7 @@
# 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 @@ def test_can_delete(self):
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')
Please sign in to comment.
Something went wrong with that request. Please try again.