Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin custom javascript load order

I am using jquery to add a few features onto some fields in the django admin, inlcuding my code by using something like the following:

class SomeAdmin(admin.ModelAdmin):
    class Media:
        js = (
                "/static/js/lib/jquery-1.3.2.min.js",
                "/static/js/admin/app/model.js"
            )
            ...
            ..
            .

It seems the admin includes all the normal js files:

<script type="text/javascript" src="/media/js/core.js"></script>
<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
<script type="text/javascript" src="/media/js/getElementsBySelector.js"></script>
<script type="text/javascript" src="/media/js/actions.js"></script>
<script type="text/javascript" src="/media/js/urlify.js"></script>

Then any custom ones you specify as above, and then if you have specified any filter_horizontal/vertical fields, the following

<script src="/media/js/SelectBox.js" type="text/javascript"/>
<script src="/media/js/SelectFilter2.js" type="text/javascript"/>

Which is a touch annoying as I would like to modify the resulting pair of select boxes.

Is it possible to change the order of the tags in the django admin?

Failing that, is it possible in jquery to have some code run after everything else, I normally use $(document).ready(....), are there any events fired after this?

extra info

Quick update incase anyone wanted to the route alex vasi suggested spelt out, you can extend the admin templates by using a file like:

{% extends "admin/change_form.html" %}

{% block extrahead %}{{ block.super }}
    <script type="text/javascript" src="/static/js/admin/app/model/somefile.js"></script>
{% endblock %}

I placed this in /path/to/project/templates/admin/app/model/change_form.html, and its done.

like image 756
sjh Avatar asked Jul 22 '09 10:07

sjh


1 Answers

Bad solution: override admin change_list template for this model and place your script-tags in the template.

like image 89
alex vasi Avatar answered Nov 07 '22 07:11

alex vasi