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 %}
source to share
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.
source to share