Use javascript, css in admin

Posted: June 2nd, 2010 | Author: Davo | Filed under: Django | Tags: , , , | No Comments »

Ever wanted to use your own JavaScript OR CSS inside the built in Django admin?
Well… it is possible!

All you need to do is the following:
1)
Add a admin.py (if you don’t already have yet…) for your app

from django.db import models
from django.contrib import admin

from myapp.hotels.models import Hotel

class HotelAdmin(admin.ModelAdmin):
    ...
    class Media:
        js = ("/media/javascript/yourjs.js",)

admin.site.register(Hotel, HotelAdmin)

2) Create a file yourjs.js under /media/javascript

(function($) {
    $(document).ready(function($) {
         // you can now use jquery / javascript here...
         alert('It worked.');
    });
})(django.jQuery);

3) Open the admin for your application and you should see the ‘It worked’ message.



Leave a Reply