有没有办法在django管理站点中同时拥有“另存为”和“另存并添加另一个”?
发布于 2010-02-06 05:43:34
我不认为按钮引用的URL有任何魔力,所以您可以通过简单地覆盖每个http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates的管理模板来添加另一个缺少功能的按钮
发布于 2014-03-04 19:39:37
我设法通过覆盖admin_modify.py中的默认行为解决了这个问题( this这篇文章帮助了我,但实际上对我并不起作用)
这是对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']),https://stackoverflow.com/questions/2208656
复制相似问题