5

I seem to have hit a wall trying to do a very simple thing: Integrate a js file into a Django model admin. I am adding a Media class like so:

class Media:
    css = { "all": ("job_run.css",) }
    js = ("job_run.js",)

I put both files in the same folder, but only the css gets actually "published" by the server (I can only see the job_run.css included in the chrome devtools). This is probably a file (job_run.js) location problem, but I don't seem to be able to find the right folder to put it under my projects. A second possible error is that I should specify somewhere the Media folder for inclusion. Could not find a good reference how to do so.

Any clues?

rubmz
  • 1,947
  • 5
  • 27
  • 49

1 Answers1

8

Create a folder named "static" inside your app and inside the 'static' folder create one more folder with your app_name. inside that folder create two folders 'css' and 'js'. Put your css and js file accordingly.

Then

class Media:
    css = { "all": ("app_name/css/job_run.css",) }
    js = ("app_name/js/job_run.js",)
Nitheesh MN
  • 608
  • 8
  • 18
  • 1
    Works like a charm! Thanks! Amazingly enough I managed to do it in every other way ;-) – rubmz May 06 '18 at 07:07
  • Please note you need to add this in admin.py where you register your model. ```Class ModelObject(admin.ModelAdmin): \n ... \n class Media: \n ...``` – Ishant Dahiya Jan 12 '22 at 16:28