开发者

Django grappelli adding custom js to change_form

I try to add my custom javascript to some change_form templates. Before having installed Grappelli, I could do that by extending change_form.html of admin and creating sub folders under the templates with my module names.

For example my tree hireachy was like :

+templates 
++admin_copies 
+++change_form.html (I have added extra js blocks) 
++admin 
+++employer 
++++employer 
+++++change_form.html 
++++employer_new 
+++++change_form.html

As you understand I have a model named "Employer". I can add my custom js methods under the change_form.html files. However, this kind of inheritance cause javascript/breadcrumbs problems with Grappell开发者_如何学编程i. How can I add simply my custom javascript functions for each model separetly ?


Create a subclass of ModelAdmin, and define the custom js in its Media class.

admin.py, in the same folder as the models.py that has Employer:

from django.contrib import admin
from models import Employer

class EmployerAdmin(admin.ModelAdmin):
    class Media:
        js = ("js/custom.js",) # This paths are appended to your MEDIA_URL setting

admin.site.register(Employer, EmployerAdmin)

Read more here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜