Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Save as" and "Save and add another" in Admin

Tags:

django

Is there a way to have both "save as" and "save and add another" in django admin site?

like image 692
Vitor Avatar asked Feb 05 '10 16:02

Vitor


2 Answers

I don't think the URLs the buttons reference are in any way magic so you could probably add another button with the missing functionality by simply override the admin template per http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates

like image 168
Mystic Avatar answered Oct 18 '22 04:10

Mystic


I managed to solve it by overriding the default behaviour in admin_modify.py ( this this post helped me but didn't actually work for me)

This is a modification of the original source code from django 1.6. Place it in /app/templatetags/admin_modify.py (dont forget to import it in /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

The source code had:

'show_save_and_add_another': context['has_add_permission'] and
              not is_popup and (not save_as or context['add']),
like image 26
Foo Bar User Avatar answered Oct 18 '22 03:10

Foo Bar User