Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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 authored March 27, 2010
2  django/contrib/admin/options.py
@@ -49,6 +49,7 @@ class IncorrectLookupParameters(Exception):
49 49
 
50 50
 class BaseModelAdmin(object):
51 51
     """Functionality common to both ModelAdmin and InlineAdmin."""
  52
+    __metaclass__ = forms.MediaDefiningClass
52 53
 
53 54
     raw_id_fields = ()
54 55
     fields = None
@@ -170,7 +171,6 @@ def _declared_fieldsets(self):
170 171
 
171 172
 class ModelAdmin(BaseModelAdmin):
172 173
     "Encapsulates all admin options and functionality for a given model."
173  
-    __metaclass__ = forms.MediaDefiningClass
174 174
 
175 175
     list_display = ('__str__',)
176 176
     list_display_links = ()
42  tests/regressiontests/admin_inlines/models.py
@@ -45,8 +45,46 @@ class InnerInline(admin.StackedInline):
45 45
     can_delete = False
46 46
 
47 47
 
48  
-# Test bug #12561
49  
-admin.site.register(Holder, inlines=[InnerInline])
  48
+class Holder2(models.Model):
  49
+    dummy = models.IntegerField()
  50
+
  51
+
  52
+class Inner2(models.Model):
  53
+    dummy = models.IntegerField()
  54
+    holder = models.ForeignKey(Holder2)
  55
+
  56
+class HolderAdmin(admin.ModelAdmin):
  57
+
  58
+    class Media:
  59
+        js = ('my_awesome_admin_scripts.js',)
  60
+
  61
+class InnerInline2(admin.StackedInline):
  62
+    model = Inner2
  63
+
  64
+    class Media:
  65
+        js = ('my_awesome_inline_scripts.js',)
  66
+
  67
+class Holder3(models.Model):
  68
+    dummy = models.IntegerField()
  69
+
  70
+
  71
+class Inner3(models.Model):
  72
+    dummy = models.IntegerField()
  73
+    holder = models.ForeignKey(Holder3)
  74
+
  75
+class InnerInline3(admin.StackedInline):
  76
+    model = Inner3
  77
+
  78
+    class Media:
  79
+        js = ('my_awesome_inline_scripts.js',)
  80
+
  81
+# Test bug #12561 and #12778
  82
+# only ModelAdmin media
  83
+admin.site.register(Holder, HolderAdmin, inlines=[InnerInline])
  84
+# ModelAdmin and Inline media
  85
+admin.site.register(Holder2, HolderAdmin, inlines=[InnerInline2])
  86
+# only Inline media
  87
+admin.site.register(Holder3, inlines=[InnerInline3])
50 88
 
51 89
 __test__ = {'API_TESTS': """
52 90
 
36  tests/regressiontests/admin_inlines/tests.py
@@ -2,6 +2,7 @@
2 2
 
3 3
 # local test models
4 4
 from models import Holder, Inner, InnerInline
  5
+from models import Holder2, Inner2, Holder3, Inner3
5 6
 
6 7
 class TestInline(TestCase):
7 8
     fixtures = ['admin-views-users.xml']
@@ -28,3 +29,38 @@ def test_can_delete(self):
28 29
         actual = inner_formset.can_delete
29 30
         self.assertEqual(expected, actual, 'can_delete must be equal')
30 31
 
  32
+class TestInlineMedia(TestCase):
  33
+    fixtures = ['admin-views-users.xml']
  34
+
  35
+    def setUp(self):
  36
+
  37
+        result = self.client.login(username='super', password='secret')
  38
+        self.failUnlessEqual(result, True)
  39
+
  40
+    def tearDown(self):
  41
+        self.client.logout()
  42
+
  43
+    def test_inline_media_only_base(self):
  44
+        holder = Holder(dummy=13)
  45
+        holder.save()
  46
+        Inner(dummy=42, holder=holder).save()
  47
+        change_url = '/test_admin/admin/admin_inlines/holder/%i/' % holder.id
  48
+        response = self.client.get(change_url)
  49
+        self.assertContains(response, 'my_awesome_admin_scripts.js')
  50
+
  51
+    def test_inline_media_only_inline(self):
  52
+        holder = Holder3(dummy=13)
  53
+        holder.save()
  54
+        Inner3(dummy=42, holder=holder).save()
  55
+        change_url = '/test_admin/admin/admin_inlines/holder3/%i/' % holder.id
  56
+        response = self.client.get(change_url)
  57
+        self.assertContains(response, 'my_awesome_inline_scripts.js')
  58
+
  59
+    def test_all_inline_media(self):
  60
+        holder = Holder2(dummy=13)
  61
+        holder.save()
  62
+        Inner2(dummy=42, holder=holder).save()
  63
+        change_url = '/test_admin/admin/admin_inlines/holder2/%i/' % holder.id
  64
+        response = self.client.get(change_url)
  65
+        self.assertContains(response, 'my_awesome_admin_scripts.js')
  66
+        self.assertContains(response, 'my_awesome_inline_scripts.js')

0 notes on commit 5a6446b

Please sign in to comment.
Something went wrong with that request. Please try again.