title: Django: Best Way to Add Javascript to Custom Widgets
body: <p>I'm writing a custom widget that requires some supporting javascript code that I need output somehwere.</p>
  
  <p>The options are:</p>
  
  <ol>
  <li>Dump it right after the html code.</li>
  <li>Append it to the form's media.</li>
  <li>Append it to a global <code>onReady</code> section.</li>
  </ol>
  
  <p>My gut instinct is to avoid things like:</p>
  
  <pre><code>&lt;!-- original widget output --&gt;
  &lt;input id="date" /&gt;
  &lt;-- Appended javascript --&gt;
  &lt;script type="text/javascript"&gt;
  jQuery('#date').datepicker()
  &lt;/script&gt; 
  </code></pre>
  
  <p>Instead, I've opted for item 3) most recently in my PHP projects. Does Django have a nice way of doing 2 or 3? I'm hoping that I can utilize this methodology from the context of my widget's <code>render</code> function. This may preclude option 2) if my widget doesn't have a any idea of the form it's on.</p>