Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Jannis Leidel authored March 21, 2010
2  django/contrib/admin/options.py
@@ -58,6 +58,7 @@ class IncorrectLookupParameters(Exception):
58 58
 
59 59
 class BaseModelAdmin(object):
60 60
     """Functionality common to both ModelAdmin and InlineAdmin."""
  61
+    __metaclass__ = forms.MediaDefiningClass
61 62
 
62 63
     raw_id_fields = ()
63 64
     fields = None
@@ -186,7 +187,6 @@ def get_readonly_fields(self, request, obj=None):
186 187
 
187 188
 class ModelAdmin(BaseModelAdmin):
188 189
     "Encapsulates all admin options and functionality for a given model."
189  
-    __metaclass__ = forms.MediaDefiningClass
190 190
 
191 191
     list_display = ('__str__',)
192 192
     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 3f4fef4

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