2012-02-07 20 views
12

Me gustaría agregar un botón adicional a la fila de envío en django. Estándar obtenemos "eliminar", "guardar", "guardar y continuar editando" y "guardar y agregar otro". A este conjunto me gustaría agregar otro botón que llamaría una función en el modelo.Cómo agregar el botón al contexto "submit_row" en django

Por lo que yo entiendo, la plantilla change_form se genera en uno de los . El contexto submit_row se pasa como contexto.

Quiero editar el contexto de la vista de administrador. ¿Dónde puedo encontrarlo en mi sistema de archivos?

+0

Cuando dices "¿Dónde puedo encontrarlo en mi filesytem?" te refieres a la plantilla de administrador de formulario de cambio? – nabucosound

+0

no me refiero a la vista que representa el changeform.html con el submit_row como su contexto – jorrebor

+0

¿Ha resuelto esto? Si es así, ¿podría publicar su solución? – AgDude

Respuesta

12

De lo que puedo decir, hay dos archivos pertinentes. La primera es

.../django/contrib/admin/templatetags/admin_modify.py 

que tiene la siguiente sección:

@register.inclusion_tag('admin/submit_line.html', takes_context=True) 
def submit_row(context): 
    """ 
    Displays the row of buttons for delete and save. 
    """ 
    opts = context['opts'] 
    change = context['change'] 
    is_popup = context['is_popup'] 
    save_as = context['save_as'] 
    return { 
     'onclick_attrib': (opts.get_ordered_objects() and change 
          and 'onclick="submitOrderForm();"' or ''), 
     'show_delete_link': (not is_popup and context['has_delete_permission'] 
           and (change or context['show_delete'])), 
     'show_save_as_new': not is_popup and change and save_as, 
     'show_save_and_add_another': context['has_add_permission'] and 
          not is_popup and (not save_as or context['add']), 
     'show_save_and_continue': not is_popup and context['has_change_permission'], 
     'is_popup': is_popup, 
     'show_save': True 
    } 

Y el segundo es

.../django/contrib/admin/templates/admin/submit_line.html 

que es el siguiente:

{% load i18n %} 
<div class="submit-row"> 
{% 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 %} 
</div> 

probablemente puede agregue algunos html personalizados a la segunda archivo para mostrar nuevos botones.

Cuestiones relacionadas