[Answer]-Django: Is possible to execute javascript or jquery directly from Media subclass?

1👍

It’s crazy and you should not do that, but you can actually.

class MyForm(forms.Form):

#Here for example only one input field...

class Media:
    js = (
        'http://code.jquery.com/jquery-1.8.3.js',
        'http://code.jquery.com/ui/1.10.1/jquery-ui.js',
        'load_my_plugin_here.js" onload="$("#my_text_box").my_plugin_apply();',
        )

I’ve tested that on django 1.4.5 and of course $(document).bind(‘ready’, function() {}); might be usefull (didn’t test that).

The more proper solution will be to add this line into it’s own javascript and include that to your class or if you prefer modify html for admin that will execute line.

Leave a comment