views:

243

answers:

2

I was wondering if there is a way to put a "Clear Form" button on the admin forms of the apps in django?

A: 

In your templates directory create a folder admin, in this create a file submit_line.html, paste this code in there (this is actually the original submit_line with the last <input... statement added:

{% load i18n %}
<div class="submit-row" {% if is_popup %}style="overflow: auto;"{% endif %}>
{% if show_save %}<input type="submit" value="{% trans 'Save' %}" class="default" name="_save" {{ onclick_attrib }}/>{% endif %}
{% if show_delete_link %}<p class="deletelink-box"><a href="delete/" class="deletelink">{% trans "Delete" %}</a></p>{% endif %}
{% if show_save_as_new %}<input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew" {{ onclick_attrib }}/>{%endif%}
{% if show_save_and_add_another %}<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother" {{ onclick_attrib }} />{% endif %}
{% if show_save_and_continue %}<input type="submit" value="{% trans 'Save and continue editing' %}" name="_continue" {{ onclick_attrib }}/>{% endif %}
<input type="reset" value="Reset form" />
</div>

Now, while this will do what you want, the Reset Form button will appear not to be clickable in some browsers (some effect is disabled). It will however work. You can also replace the input by <button type="reset">Reset form</button> but I find this rather ugly. Finally, you could also search the stylesheets to see which code fails (it's something like a input['reset'] that's missing somewhere). But anyway, this works, have fun with it

KillianDS
A: 

Hi,

I tried to do the same things but with a button who send mail with form data....

I put my button in this submit_line.html:

<input type="submit" value="Transmettre le contact" class="default" name="_transfert"/> 

but now i try to tell my button to do something when clik on it...

In the other buton i see only name="_something" for example : for saving, the button save use : name="_save" and call the method save_model from AdminModel...

How can i link my send_mail button to an Admin method who send my data ?

I need help

Thx

laurent