Ticket #12778: django-bug-12778.diff

File django-bug-12778.diff, 4.1 KB (added by Paul McLanahan, 15 years ago)

Proposed fix and tests

  • django/contrib/admin/options.py

     
    5858
    5959class BaseModelAdmin(object):
    6060    """Functionality common to both ModelAdmin and InlineAdmin."""
     61    __metaclass__ = forms.MediaDefiningClass
    6162
    6263    raw_id_fields = ()
    6364    fields = None
     
    186187
    187188class ModelAdmin(BaseModelAdmin):
    188189    "Encapsulates all admin options and functionality for a given model."
    189     __metaclass__ = forms.MediaDefiningClass
    190190
    191191    list_display = ('__str__',)
    192192    list_display_links = ()
  • tests/regressiontests/admin_inlines/tests.py

     
    22
    33# local test models
    44from models import Holder, Inner, InnerInline
     5from models import Holder2, Inner2, Holder3, Inner3
    56
    67class TestInline(TestCase):
    78    fixtures = ['admin-views-users.xml']
     
    2829        actual = inner_formset.can_delete
    2930        self.assertEqual(expected, actual, 'can_delete must be equal')
    3031
     32class 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')
     67 No newline at end of file
  • tests/regressiontests/admin_inlines/models.py

     
    4545    can_delete = False
    4646
    4747
    48 # Test bug #12561
    49 admin.site.register(Holder, inlines=[InnerInline])
     48class Holder2(models.Model):
     49    dummy = models.IntegerField()
    5050
     51
     52class Inner2(models.Model):
     53    dummy = models.IntegerField()
     54    holder = models.ForeignKey(Holder2)
     55
     56class HolderAdmin(admin.ModelAdmin):
     57   
     58    class Media:
     59        js = ('my_awesome_admin_scripts.js',)
     60
     61class InnerInline2(admin.StackedInline):
     62    model = Inner2
     63   
     64    class Media:
     65        js = ('my_awesome_inline_scripts.js',)
     66       
     67class Holder3(models.Model):
     68    dummy = models.IntegerField()
     69
     70
     71class Inner3(models.Model):
     72    dummy = models.IntegerField()
     73    holder = models.ForeignKey(Holder3)
     74
     75class 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
     83admin.site.register(Holder, HolderAdmin, inlines=[InnerInline])
     84# ModelAdmin and Inline media
     85admin.site.register(Holder2, HolderAdmin, inlines=[InnerInline2])
     86# only Inline media
     87admin.site.register(Holder3, inlines=[InnerInline3])
     88
    5189__test__ = {'API_TESTS': """
    5290
    5391# Regression test for #9362
Back to Top