django-jazzmin icon indicating copy to clipboard operation
django-jazzmin copied to clipboard

Support for django-smart-selects (feature)

Open kmandina opened this issue 3 years ago • 5 comments

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.

kmandina avatar Apr 06 '21 15:04 kmandina

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

RyanLoil avatar Aug 10 '21 15:08 RyanLoil

OK, the second problem is not a problem - the original admin is not working either, they didn't make that function.

RyanLoil avatar Aug 10 '21 18:08 RyanLoil

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?

willianmascimiano avatar Nov 14 '22 17:11 willianmascimiano

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'],
     ...
    }
]

mardukbp avatar Jul 21 '23 08:07 mardukbp

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'],
     ...
    }
]

Excelente!!! This works for me.

emilioferreyra avatar Aug 03 '23 21:08 emilioferreyra

@mardukbp Thanks for finding the solution to this problem. Feel free to raise a PR to add to the documentation for others to find 🙂

jamesgilmorelyst avatar Mar 23 '24 16:03 jamesgilmorelyst