首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Admin中的"Save as“和"Save and add another”

Admin中的"Save as“和"Save and add another”
EN

Stack Overflow用户
提问于 2010-02-06 00:32:46
回答 2查看 2.9K关注 0票数 6

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

EN

回答 2

Stack Overflow用户

发布于 2010-02-06 05:43:34

我不认为按钮引用的URL有任何魔力,所以您可以通过简单地覆盖每个http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates的管理模板来添加另一个缺少功能的按钮

票数 1
EN

Stack Overflow用户

发布于 2014-03-04 19:39:37

我设法通过覆盖admin_modify.py中的默认行为解决了这个问题( this这篇文章帮助了我,但实际上对我并不起作用)

这是对django 1.6的原始源代码的修改。将其放入/app/templatetags/admin_modify.py (别忘了在/app/templatetags/__init__.py中导入)

代码语言:javascript
复制
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

源代码包含:

代码语言:javascript
复制
'show_save_and_add_another': context['has_add_permission'] and
              not is_popup and (not save_as or context['add']),
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2208656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档