- Author:
- christian
- Posted:
- October 1, 2007
- Language:
- JavaScript
- Version:
- Not specified
- Score:
- 5 (after 5 ratings)
Adds a shortcut to edit releated objects right/ForeignKey fields. an edit symbol will be shown right next to the "add annother" link on all select boxes, with opens the releated object currently selected in a popup window. depends on jquery
Add this to the head of "templates/admin/base.html".
you may need to add
<script type="text/javascript" src="/path/to/jquery.js"></script>
before it
1 2 3 4 5 6 7 8 9 10 11 12 13 | <script type="text/javascript">
$(function(){
$("select+a.add-another").each(function(){
$(this).after(" <a class='changelink' href='#'></a>");
$(this).next().click(function(){
var link = ($(this).prev().attr('href')+'../'+$(this).prev().prev().attr('value'));
var win = window.open(link + '?_popup=1', link, 'height=600,width=1000,resizable=yes,scrollbars=yes');
win.focus();
return false;
});
});
});
</script>
|
More like this
- Django Collapsed Stacked Inlines by applecat 1 year, 9 months ago
- Django Collapsed Stacked Inlines by mkarajohn 3 years, 10 months ago
- Dynamically adding forms to a formset. OOP version. by halfnibble 9 years, 6 months ago
- Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 11 years, 7 months ago
- Django admin inline ordering - javascript only implementation by ojhilt 11 years, 11 months ago
Comments
Thanks! That's exactly what I was looking for...
I modified it a little so that if nothing's selected in the FK field it just opens the generic 'select object to change' popup (instead of throwing an error).
` $(function(){
`
#
With this two lines patch, Save button close the window.
#
Two little changes: added a title attribute to the edit icon and a simple if that prevents opening a new window in case nothing is selected:
#
Probably a noob problem, but the snippet has no effect for me with Django 1.3. The script shows up in the head section, and I've added the jquery line, but no markup is added after the add-another links. Any ideas?
#
Scratch my comment, I had the wrong path to my jquery.js. Snippet works great under 1.3.
#
Modified for rawid fields. Converted $s to django.jQuery for placing it into change_form.html. Works with Django 1.4b1.
#
Another workaround, if want to close popup window after save and you don't want to patch django/contrib/admin/options/.py
Extend original admin/change_list.html in following way.
#
Please login first before commenting.