Django admin add custom button on form change based on form field value

I have an application that overrides a Django form change form. What I want to change are the submit buttons at the bottom. Pod change_form.html

in django app:

{% extends "admin/change_form.html" %}
{% block submit_buttons_bottom %} 
    ## add some buttons
{% endblock %}

      

The button I want to show / add depends on the value of a specific field in the name names status. How can I get the value of a field in a template ... something like :

{% if form.field.status == 'unresolved' %}
    <input type="submit" value="Mark as resolved" class="default" name="_save" />
{% endif %}

      

UPDATE:

I have no errors. It just doesn't show anything.

Quoting through var 'adminform' will take me to the correct field

{% for fieldset in adminform %}
    {% for line in fieldset %}
        {% for field in line %}
            {% if field.field.name == 'status' %}
                this is status {{ field.field.name }} - {{ field.contents }}
            {% endif %}
        {% endfor %}
    {% endfor %}
{% endfor %}

      

But I want to access it directly. Something like:

{% if adminform.0.0.field.status == 'unresolved' %}
    <input type="submit" value="Mark as resolved" class="default" name="_save" />
{% endif %}

      

+3


source to share


2 answers


Try changing the instruction if

to

{% if adminform.status.value == 'unresolved' %}

      



I'm guessing, but I think the variable adminform

is probably just a form. Take a look at this section of the documentation to see the attributes of form fields.

0


source


This should work:

{% if adminform.form.status.value == 'unresolved' %}

      



or if the field is read-only, there is another way:

{% if adminform.form.instance.status == 'unresolved' %}

      

0


source







All Articles