[Django]-Adding an extra button to one object in django admin

4👍

You can do it using javascript like this:

/static/js/useful.js

$(document).ready(function ($) {
    $('input[name="_addanother"]').before('<input type="submit" name="_use" value="Useful functionality"/>');
});

and in your ModelAdmin add:

class MyModelAdmin(admin.ModelAdmin):
     class Media:
        js = ('/static/js/useful.js',)

0👍

You should be able to access the original object in change_view‘s context through original. For example {{ original.id }} should print its id!

Leave a comment