[Answered ]-How to add javascript to the change_form.html for block content in django

2👍

You don’t need content block, there is head block, you could place your js there. But that js thing that prevents some users from modifying some fields could be hacked easily.

{% block extrahead %}
    {{ block.super }}

    <script type="text/javascript">
        $(function() {
            {% if user.get_profile.is_customer %}
                $('#id_of_field_block').hide();
            {% endif %}
        });
    </script>
{% endblock extrahead %}

Also you could change change_form.html template and override content block, getting original file content as source and change fieldset template fieldset.html (or you could override only fieldset.html, I’m not sure). This template iterates over fields and there you could add some checking.

Leave a comment