I'm writing a custom widget that requires some supporting javascript code that I need output somehwere.

The options are:

  1. Dump it right after the html code.
  2. Append it to the form's media.
  3. Append it to a global onReady section.

My gut instinct is to avoid things like:

<!-- original widget output -->
<input id="date" />
<-- Appended javascript -->
<script type="text/javascript">
jQuery('#date').datepicker()
</script> 

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 render function. This may preclude option 2) if my widget doesn't have a any idea of the form it's on.

Edit
Report