I should probably mention that I've been using Django for a total of
something like 20 work hours :) I'm not sure this follows your style of
code, and there's quite possibly things I haven't thought about, but
given that I think this is a very useful enhancement that was very
quick to add I was hoping that you might consider incorporating it.
I've included the svn diff output below, but it will be mangled as I
post this message I guess. I'm not expecting this code to make it into
the actual source, but I would very much appreciate it if the feature
itself was added by someone.
Index: contrib/admin/media/js/admin/RelatedObjectLookups.js
===================================================================
--- contrib/admin/media/js/admin/RelatedObjectLookups.js
(revision 3237)
+++ contrib/admin/media/js/admin/RelatedObjectLookups.js
(working copy)
@@ -16,14 +16,18 @@
return false;
}
-function dismissRelatedLookupPopup(win, chosenId) {
+function dismissRelatedLookupPopup(win, chosenId, chosenName) {
var name = win.name.replace(/___/g, '.');
var elem = document.getElementById(name);
+ var nameElem = document.getElementById("view_" + name);
if (elem.className.indexOf('vRawIdAdminField') != -1 &&
elem.value) {
elem.value += ',' + chosenId;
} else {
document.getElementById(name).value = chosenId;
}
+ if(nameElem) {
+ nameElem.innerHTML = chosenName;
+ }
win.close();
}
Index: contrib/admin/templatetags/admin_list.py
===================================================================
--- contrib/admin/templatetags/admin_list.py (revision 3237)
+++ contrib/admin/templatetags/admin_list.py (working copy)
@@ -169,8 +169,9 @@
first = False
url = cl.url_for_result(result)
result_id = str(getattr(result, pk)) # str() is needed in
case of 23L (long ints)
+ result_name = str(result)
yield ('<th%s><a href="%s"%s>%s</a></th>' % \
- (row_class, url, (cl.is_popup and '
onclick="opener.dismissRelatedLookupPopup(window, %r); return false;"'
% result_id or ''), result_repr))
+ (row_class, url, (cl.is_popup and '
onclick="opener.dismissRelatedLookupPopup(window, %r, %r); return
false;"' % (result_id or '', result_name)), result_repr))
else:
yield ('<td%s>%s</td>' % (row_class, result_repr))
Index: contrib/admin/templates/widget/foreign.html
===================================================================
--- contrib/admin/templates/widget/foreign.html (revision 3237)
+++ contrib/admin/templates/widget/foreign.html (working copy)
@@ -10,11 +10,14 @@
{% if bound_field.needs_add_label %}
<a href="{{ bound_field.related_url }}add/" class="add-another"
id="add_{{ bound_field.element_id }}" onclick="return
showAddAnotherPopup(this);"> <img src="{% admin_media_prefix
%}img/admin/icon_addlink.gif" width="10" height="10" alt="Add
Another"/></a>
{% endif %}{% endif %}
+{% if not change %}
+ <strong id="view_{{ bound_field.element_id }}"></strong>
+{% endif %}
{% if change %}
{% if bound_field.field.primary_key %}
{{ bound_field.original_value }}
{% endif %}
{% if bound_field.raw_id_admin %}
- {% if bound_field.existing_display %} <strong>{{
bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %}
+ {% if bound_field.existing_display %} <strong id="view_{{
bound_field.element_id }}">{{
bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %}
{% endif %}
{% endif %}