更新时间:2023-12-01 23:11:58
除了(有点尴尬)黑客风格之外,您可以直接覆盖模板标签。
更推荐通常覆盖模板。
Beside its (a bit awkward) hacking style, you could aslo override the template tag directly. Normally overriding template is more recommended.
# put this in some app such as customize/templatetags/admin_modify.py and place the app
# before the 'django.contrib.admin' in the INSTALLED_APPS in settings
from django.contrib.admin.templatetags.admin_modify import *
from django.contrib.admin.templatetags.admin_modify import submit_row as original_submit_row
# or
# original_submit_row = submit_row
@register.inclusion_tag('admin/submit_line.html', takes_context=True)
def submit_row(context):
ctx = original_submit_row(context)
ctx.update({
'show_save_and_add_another': context.get('show_save_and_add_another', ctx['show_save_and_add_another']),
'show_save_and_continue': context.get('show_save_and_continue', ctx['show_save_and_continue'])
})
return ctx