Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.1.X] Fixed #12778 - Added media handling abilities to admin inline…

…s. Thanks for the patch, pmclanahan.

Backport from trunk, r12825.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12864 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5a6446b4437d123f1731d66bba0f3c0c9bc9d353 1 parent 5fab617
Jannis Leidel jezdez authored
2  django/contrib/admin/options.py
View
@@ -49,6 +49,7 @@ class IncorrectLookupParameters(Exception):
class BaseModelAdmin(object):
"""Functionality common to both ModelAdmin and InlineAdmin."""
+ __metaclass__ = forms.MediaDefiningClass
raw_id_fields = ()
fields = None
@@ -170,7 +171,6 @@ def _declared_fieldsets(self):
class ModelAdmin(BaseModelAdmin):
"Encapsulates all admin options and functionality for a given model."
- __metaclass__ = forms.MediaDefiningClass
list_display = ('__str__',)
list_display_links = ()
42 tests/regressiontests/admin_inlines/models.py
View
@@ -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': """
36 tests/regressiontests/admin_inlines/tests.py
View
@@ -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.