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?

1

1 Answer 1

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",)
Sign up to request clarification or add additional context in comments.

2 Comments

Works like a charm! Thanks! Amazingly enough I managed to do it in every other way ;-)
Please note you need to add this in admin.py where you register your model. Class ModelObject(admin.ModelAdmin): \n ... \n class Media: \n ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.