Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This isn't possible with an 'out of the box' option as far as I can tell, but this is how I'd go about doing what you want to do.</p> <p>The bit of code we care about is <a href="https://github.com/django/django/blob/master/django/contrib/admin/templatetags/admin_modify.py#L23" rel="nofollow noreferrer">this templatetag</a> - this seems to override <code>show_save_and_add_another</code> and <code>show_save_and_continue</code> regardless of what you have set it to. It also creates a whole new context and copies only certain values across (not clear what the justification for this is), so you'll have to modify it to get what you need. </p> <p>So:</p> <ol> <li>Create a templatetag that replicates the functionality of the default tag, either by reusing the existing one (see <a href="https://stackoverflow.com/a/13106661/23746">okm's example</a>) or by duplicating it entirely. The only change here is that it should either keep your <code>show_save_and_add_another</code> from the original context without overwriting it, or pass through your own <code>really_hide_save_and_add_another_damnit</code> context variable.</li> <li>Replace change_form.html to include and use your own templatetag, replacing <code>submit_row</code> with it.</li> <li>Update change_form.html if you've gone for the option of using an extra context variable, wrapping the buttons with another conditional statement.</li> </ol> <p>Then, regardless of what option you went for, update your ModelAdmin with something like (based on <a href="https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.history_view" rel="nofollow noreferrer">this from the Django docs</a>):</p> <pre><code>class MyModelAdmin(admin.ModelAdmin): # ... def change_view(self, request, object_id, form_url='', extra_context=None): extra_context = extra_context or {} extra_context['show_save_and_add_another'] = False # or extra_context['really_hide_save_and_add_another_damnit'] = True return super(MyModelAdmin, self).change_view(request, object_id, form_url, extra_context=extra_context) </code></pre> <p><strong>Updated:</strong> Original response didn't take in to account the submit_row not passing along any the whole original context.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload