«Сохранить как» и «Сохранить и добавить еще» в Admin - PullRequest
6 голосов
/ 05 февраля 2010

Есть ли способ сделать «сохранить как» и «сохранить и добавить еще» на сайте администратора django?

Ответы [ 2 ]

1 голос
/ 04 марта 2014

Мне удалось решить эту проблему путем переопределения поведения по умолчанию в admin_modify.py ( этот этот пост помог мне, но на самом деле не работал для меня)

Это модификация исходного исходного кода 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']),
1 голос
/ 06 февраля 2010

Я не думаю, что URL-адреса, на которые ссылаются кнопки, в какой-то степени волшебны, так что вы, вероятно, могли бы добавить еще одну кнопку с отсутствующей функциональностью, просто переопределив шаблон администратора для http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...