2012-02-07 27 views
12

Tôi muốn thêm nút bổ sung vào hàng gửi trong django. Tiêu chuẩn chúng tôi nhận được "xóa", "lưu", "lưu và tiếp tục chỉnh sửa" và "lưu và thêm một tệp khác". Để thiết lập này tôi muốn thêm một nút khác mà sẽ gọi một chức năng trên mô hình.Cách thêm nút vào ngữ cảnh "submit_row" trong django

Theo như tôi hiểu, mẫu change_form được tạo tại một trong số admin.views. Ngữ cảnh submit_row được chuyển thành ngữ cảnh.

Tôi muốn chỉnh sửa ngữ cảnh của chế độ xem quản trị viên. Tôi có thể tìm thấy nó trong hệ thống tập tin của tôi ở đâu?

+0

Khi bạn nói "Tôi có thể tìm thấy nó trong tệp của mình ở đâu?" bạn có nghĩa là mẫu quản trị biểu mẫu thay đổi? – nabucosound

+0

không có nghĩa là chế độ xem hiển thị changeform.html với submit_row là ngữ cảnh của nó – jorrebor

+0

Bạn đã giải quyết vấn đề này chưa? Nếu vậy, bạn có thể vui lòng gửi giải pháp của bạn. – AgDude

Trả lời

12

Từ những gì tôi có thể nói, có hai tập tin có liên quan. Đầu tiên là

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

trong đó có các phần sau:

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

Và thứ hai là

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

đó là những điều sau:

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

Bạn có thể có lẽ chỉ thêm một số html tùy chỉnh vào thứ hai để hiển thị các nút mới.

Các vấn đề liên quan