﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
6723	djangonewforms-admin edit related feature (JS)	zbyszek	nobody	"i created a litle '''modification''' (edit feature) for related objects. only thing that i made is an function for js, and added '''only 2 lines of code''' in widgets.py in contrib/admin/. '''this does not affect anything else'''. so '''it should be safe to use'''. maybe someone could make it better or add delete feautre?
this is for the djangonewforms-admin.

so the code for the widgets.py would change to:
{{{
class RelatedFieldWidgetWrapper(object):
    """"""
    This class is a wrapper whose __call__() method mimics the interface of a
    Widget's render() method.
    """"""
    def __init__(self, render_func, rel, admin_site):
        self.render_func, self.rel = render_func, rel
        # so we can check if the related object is registered with this AdminSite
        self.admin_site = admin_site

    def __call__(self, name, value, *args, **kwargs):
        from django.conf import settings
        rel_to = self.rel.to
        related_url = '../../../%s/%s/' % (rel_to._meta.app_label, rel_to._meta.object_name.lower())
        output = [self.render_func(name, value, *args, **kwargs)]
        if rel_to in self.admin_site._registry: # If the related object has an admin interface:
            # TODO: ""id_"" is hard-coded here. This should instead use the correct
            # API to determine the ID dynamically.
            output.append(u'<a href=""%sadd/"" class=""add-another"" id=""add_id_%s"" onclick=""return showAddAnotherPopup(this);""> ' % \
                (related_url, name))
            output.append(u'<img src=""%simg/admin/icon_addlink.gif"" width=""10"" height=""10"" alt=""Add Another""/></a>' % settings.ADMIN_MEDIA_PREFIX)
            output.append('<a href=""%s"" class=""related-lookup"" id=""edit_id_%s"" onclick=""return showEditSelectedPopup(this);""> ' % \
            (related_url, name))# this added someone can change the class name ;/
            output.append(u'<img src=""%simg/admin/icon_changelink.gif"" width=""10"" height=""10"" alt=""Edit Selected""/></a>' % settings.ADMIN_MEDIA_PREFIX)#this added
        return mark_safe(u''.join(output))

    def __deepcopy__(self, memo):
        # There's no reason to deepcopy admin_site, etc, so just return self.
        memo[id(self)] = self
        return self
}}}

and the function for the JS would be(a bit modified  showAddAnotherPopup() function):
{{{
function showEditSelectedPopup(triggeringLink) {
    var name = triggeringLink.id.replace(/^edit_/, '');
    name = name.replace(/\./g, '___');
	var elem = document.getElementById(name);
	var id = elem.options[elem.selectedIndex].value;
	if (id == '')
		return false;
	
    href = triggeringLink.href +id+'/';
    if (href.indexOf('?') == -1) {
        href += '?_popup=1';
    } else {
        href  += '&_popup=1';
    }
    var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
    win.focus();
    return false;
}
}}}


sorry for not using diffs etc , but i'm kinda new in all this:"	Uncategorized	closed	Forms	newforms-admin	Normal	duplicate	newforms-admin foreignkey edit nfa-someday		Design decision needed	0	0	0	0	0	0
