title: How can I override the "media" property of Django's ModelAdmin and make it dynamic?
body: <p>Ultimately, I'd like to include/exclude certain javascript file(s) based on... whatever.  Simply defining the Media class, by itself, won't work since that is only evaluated once. </p>
  
  <p>I know I can do this by making a custom admin template, but I'm wondering if there's a simple way to do it by just making the media property dynamic.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>from django.contrib import admin
  class MyModelAdmin(admin.ModelAdmin):
      model = MyModel
      ...
  
      @property
      def media(self):
          media = super(MyModelAdmin, self).media
          if whatever_condition_I_want:
              # somehow add "my/js/file3.js"
          return media
  
      class Media:
          css = {
              "all": (
                  "my/css/file1.css",
                  "my/css/file2.css",
              )
          }
          js = (
              "my/js/file1.js",
              "my/js/file2.js",
          )
  </code></pre>
  
  <p>And that almost works, but I found that calling <code>super(MyModelAdmin, self).media</code> ignores my current class's Media definitions. In poking around, I found that this is because the parent class's media property is wrapped by <code>django.forms.widgets.media_property</code> (via <code>MediaDefiningClass</code>) and since I'm overriding media, my media property isn't being wrapped.  I tried manually wrapping it via:</p>
  
  <pre><code>from django.forms import media_property
  MyModelAdmin.media = media_property(MyModelAdmin)
  </code></pre>
  
  <p>but media_property fails to import.</p>
  
  <p>How can I make it include my static media and my dynamic media, and how do I add my dynamic media in a way that django is happy with?</p>