2012-02-07 16 views
12

Chciałbym dodać dodatkowy przycisk do wiersza submit w django. Standard otrzymujemy "usuń", "zapisz", "zapisz i kontynuuj edycję" oraz "zapisz i dodaj kolejny". Do tego zestawu chciałbym dodać kolejny przycisk, który wywołałby funkcję w modelu.Jak dodać przycisk do kontekstu "submit_row" w django

O ile rozumiem, szablon change_form jest generowany w jednym z admin.views. Kontekst submit_row jest przekazywany jako kontekst.

Chcę edytować kontekst widoku administratora. Gdzie mogę go znaleźć w moim systemie plików?

+0

Kiedy mówisz "Gdzie mogę znaleźć to w moim systemie plików?" masz na myśli szablon zmiany formy administratora? – nabucosound

+0

no mam na myśli widok, który renderuje plik changeform.html z parametrem submit_row jako kontekstem. – jorrebor

+0

Rozwiązałeś to? Jeśli tak, czy mógłbyś opublikować swoje rozwiązanie. – AgDude

Odpowiedz

12

Z tego co mogę powiedzieć, istnieją dwa istotne pliki. Pierwszym z nich jest

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

który posiada następującą sekcję:

@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 
    } 

A drugie

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

który jest następujący:

{% 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> 

prawdopodobnie można po prostu dodaj niestandardowy html do drugiego plik do wyświetlania nowych przycisków.

Powiązane problemy