2010-02-05 51 views
6

有沒有在django管理站點同時具有「另存爲」和「保存並添加另一個」的方法?「另存爲」和「保存並添加另一個」在管理

+0

你會怎麼做保存爲?每個表單要麼保存一個新對象並返回到列表(保存),保存一個新對象並返回到空白的新對象表單(保存並添加另一個表單),要麼保存並保留在該對象的編輯頁面中(保存並繼續編輯)。 – 2010-02-05 17:30:56

+0

如果您將save_as = True放入您的admin.py,您將獲得另存爲按鈕。但是這樣做是取消保存並通過另存爲添加另一個按鈕。但我希望能夠有兩個選擇。 – Vitor 2010-02-05 17:54:39

回答

1

的管理模板與缺失的功能添加另一個按鈕我設法解決它通過覆蓋默認行爲admin_modify.pythis這篇文章幫了我,但實際上並沒有爲我工作)

這是對django 1.6原始源代碼的修改。將其放置在/app/templatetags/admin_modify.py(不要忘記將其導入/app/templatetags/__init__.py

from django.contrib.admin.templatetags import admin_modify 

@admin_modify.register.inclusion_tag('admin/submit_line.html', takes_context=True) 
def submit_row(context): 
    opts = context['opts'] 
    change = context['change'] 
    is_popup = context['is_popup'] 
    save_as = context['save_as'] 
    ctx = { 
     'opts': opts, 
     'show_delete_link': (not is_popup and context['has_delete_permission'] 
           and change and context.get('show_delete', True)), 
     '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, 
     'show_save_and_continue': not is_popup and context['has_change_permission'], 
     'is_popup': is_popup, 
     'show_save': True, 
     'preserved_filters': context.get('preserved_filters'), 
    } 
    if context.get('original') is not None: 
     ctx['original'] = context['original'] 
    return ctx 

admin_modify.submit_row = submit_row 

的源代碼有:

'show_save_and_add_another': context['has_add_permission'] and 
       not is_popup and (not save_as or context['add']), 
+0

我必須更改文件.../django/contrib/admin/templates/admin/submit_line.html(看到按鈕)並在/ /templatetags/__init__.py中輸入「from admin_modify import *」,它應該工作還是我錯過了什麼? – Izzy 2017-01-04 16:38:41

相關問題