管理员中的“另存为”和“另存为”

时间:2010-02-05 16:32:46

标签: django

有没有办法在django管理站点中同时“另存为”和“保存并添加另一个”?

2 个答案:

答案 0 :(得分:1)

我不认为按钮引用的URL在任何方面都是魔术,所以你可以添加另一个缺少功能的按钮,只需覆盖每个http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates的管理模板

答案 1 :(得分:1)

我设法通过覆盖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']),
相关问题