Skip to content

Instantly share code, notes, and snippets.

@hughsaunders
Created June 28, 2011 17:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hughsaunders/1051630 to your computer and use it in GitHub Desktop.
Save hughsaunders/1051630 to your computer and use it in GitHub Desktop.
Django Admin Template Override for adding edit popups to foreign key fields.
{%extends "admin/base.html" %}
{% block extrahead %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.add-another').each(function(i,o){
select_obj=$(o).parent().find('select')[0];
item_id=select_obj.options[select_obj.selectedIndex].value;
edit_url=o.href.replace('add',item_id)+"?_popup=1";
$(this).after('<span> </span><a class="edit-popup" '
+'href="'+edit_url+'"><img src="/static/admin/img/admin/'
+'icon_changelink.gif"/></a>')
})
$('.edit-popup').click(function(event){
win=window.open(this.href,'Edit Window',
'height=500,width=800,resizable=yes,scrollbars=yes')
win.focus()
event.preventDefault()
})
});
</script>
{% endblock %}
@hughsaunders
Copy link
Author

\ doesn't work as a line continuation character in JS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment