django-jazzmin
django-jazzmin copied to clipboard
Support for django-smart-selects (feature)
Hi Very good work with this project. I am using https://github.com/jazzband/django-smart-selects.git and It does't work with jazzmin
do anybody know what happens?
Greeting from Cuba.
In my app, there is several problem that I found during development with jazzmin and smart-select:
- the ChainForeignField in Admin Form is not working
- the ChainForeignField in Admin Filter is not working
For the first problem, it can be fixed by adding these following codes at the end of jazzmin template base html of which in the root of /venv/lib/jazzmin/templates/base.html
<script src="/static/smart-selects/admin/js/chainedfk.js"></script>
<script src="/static/smart-selects/admin/js/bindfields.js"></script>
For the second problem, I'm still trying to find a solution
OK, the second problem is not a problem - the original admin is not working either, they didn't make that function.
In my app, there is several problem that I found during development with jazzmin and smart-select:
- the ChainForeignField in Admin Form is not working
- the ChainForeignField in Admin Filter is not working
For the first problem, it can be fixed by adding these following codes at the end of jazzmin template base html of which in the root of /venv/lib/jazzmin/templates/base.html
<script src="/static/smart-selects/admin/js/chainedfk.js"></script>
<script src="/static/smart-selects/admin/js/bindfields.js"></script>
For the second problem, I'm still trying to find a solution
How can I setup this modification to not have problem when i download this lib again in other environment?
It is not necessary to modify the templates shipped with jazzmin. The base.html template includes a block called extrajs
near the end that allows loading JS after the whole page loaded. Using the standard Django template extension mechanism one can create a template to load the required JS files. This is done as follows.
In your BASE_DIR create the directory templates/admin
. In this directory create the template base_site.html
with the contents:
{% extends 'admin/base_site.html' %}
{% load static %}
{% block extrajs %}
{{ block.super }}
<script src="{% static "smart-selects/admin/js/chainedfk.js" %}"></script>
<script src="{% static "smart-selects/admin/js/bindfields.js" %}"></script>
{% endblock %}
For this to work make sure that in settings.py you have the following:
TEMPLATES = [
{
...
'DIRS': [BASE_DIR / 'templates'],
...
}
]
It is not necessary to modify the templates shipped with jazzmin. The base.html template includes a block called
extrajs
near the end that allows loading JS after the whole page loaded. Using the standard Django template extension mechanism one can create a template to load the required JS files. This is done as follows.In your BASE_DIR create the directory
templates/admin
. In this directory create the templatebase_site.html
with the contents:{% extends 'admin/base_site.html' %} {% load static %} {% block extrajs %} {{ block.super }} <script src="{% static "smart-selects/admin/js/chainedfk.js" %}"></script> <script src="{% static "smart-selects/admin/js/bindfields.js" %}"></script> {% endblock %}
For this to work make sure that in settings.py you have the following:
TEMPLATES = [ { ... 'DIRS': [BASE_DIR / 'templates'], ... } ]
Excelente!!! This works for me.
@mardukbp Thanks for finding the solution to this problem. Feel free to raise a PR to add to the documentation for others to find 🙂