Skip to content

Instantly share code, notes, and snippets.

@dokterbob
Created February 15, 2011 19:20
Show Gist options
  • Save dokterbob/828052 to your computer and use it in GitHub Desktop.
Save dokterbob/828052 to your computer and use it in GitHub Desktop.
Simple Django admin mixin which dynamically adds links to inline admins on the top right of the admin form.
class InlineButtonsAdminMixin(object):
"""
Mixin which dynamically adds links to inline admins on the top right of
the admin form.
"""
class Media:
js = ('js/inlinebuttons.js',)
django.jQuery(function () {
$ = django.jQuery;
var object_tools = $('.object-tools:first');
var title;
var tool_items = $('<span/>');
if (object_tools.length == 0) {
object_tools = $('<ul class="object-tools"></ul>');
$('#content-main').prepend(object_tools);
}
$('.inline-group').each(function(index) {
title = $(this).find('h2:first').text()
tool_items.append($('<li><a href="#'+this.id+'">'+title+'</a></li>'));
});
object_tools.prepend(tool_items);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment