Ticket #2569: adminforeign.3.diff
File adminforeign.3.diff, 5.1 KB (added by , 18 years ago) |
---|
-
django/db/models/fields/related.py
566 566 567 567 self.db_index = True 568 568 569 def get_related_pk(self): 570 """ Returning the primary key of the object we are related to 571 """ 572 return self.get_choices()[1][0] 573 569 574 def get_attname(self): 570 575 return '%s_id' % self.name 571 576 -
django/contrib/admin/media/js/admin/RelatedObjectLookups.js
55 55 } 56 56 win.close(); 57 57 } 58 59 function showEditPopup(triggeringLink) { 60 var name = triggeringLink.id.replace(/^edit_/,''); 61 var elem = document.getElementById(name); 62 if (elem) { 63 if (elem.nodeName == 'SELECT') { 64 var id = elem.options[elem.selectedIndex].value 65 name = name.replace(/\./g,'___'); 66 var win = window.open(triggeringLink.href + id + '/?_popup=1',name, 'height=500,width=800,resizable=yes,scrollbars=yes'); 67 return false; 68 } 69 } 70 return false; 71 } 72 73 function dismissEditPopup(win, newId, newRepr) { 74 var name = win.name.replace(/___/g, '.'); 75 var elem = document.getElementById(name); 76 if(elem) { 77 if( elem.nodeName == 'SELECT') { 78 var o = new Option(newRepr, newId); 79 elem.options[elem.selectedIndex] = o; 80 o.selected = true; 81 } 82 } 83 win.close(); 84 } -
django/contrib/admin/views/main.py
130 130 131 131 if field.rel: 132 132 self.related_url = '../../../%s/%s/' % (field.rel.to._meta.app_label, field.rel.to._meta.object_name.lower()) 133 try: 134 self.rel_to_pk = field.get_related_pk() # for one-to-one fields 135 except: 136 pass 133 137 134 138 def original_value(self): 135 139 if self.original: … … 343 347 LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, str(new_object), CHANGE, change_message) 344 348 345 349 msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': opts.verbose_name, 'obj': new_object} 350 if request.REQUEST.has_key("_popup"): 351 http_response = '<script type="text/javascript">opener.dismissEditPopup(window, %s, "%s");</script>' % \ 352 (pk_value, str(new_object).replace('"', '\\"')) 353 return HttpResponse(http_response) 346 354 if request.POST.has_key("_continue"): 347 355 request.user.message_set.create(message=msg + ' ' + _("You may edit it again below.")) 348 356 if request.REQUEST.has_key('_popup'): -
django/contrib/admin/templates/widget/one_to_one.html
1 {% load admin_modify adminmedia %} 1 2 {% if add %}{% include "widget/foreign.html" %}{% endif %} 2 {% if change %}{% if bound_field.existing_display %} <strong>{{ bound_field.existing_display|truncatewords:"14"|escape }}</strong>{% endif %}{% endif %} 3 {% if change %} 4 {% if bound_field.rel_to_pk %} <a href="{{ bound_field.related_url }}{{ bound_field.rel_to_pk}}"><strong>{{ bound_field.existing_display|truncatewords:"14"|escape }}</strong></a>{% endif %}{% endif %} -
django/contrib/admin/templates/widget/foreign.html
8 8 {% endif %} 9 9 {% else %} 10 10 {% if bound_field.needs_add_label %} 11 <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> 12 {% endif %}{% endif %} 11 <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> 12 <a href="{{ bound_field.related_url }}" class="related-lookup" id="edit_{{ bound_field.element_id }}" onclick="return showEditPopup(this);"> <img src="{% admin_media_prefix %}img/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a> 13 14 {% endif %} 15 {% endif %} 13 16 {% if change %} 14 17 {% if bound_field.field.primary_key %} 15 18 {{ bound_field.original_value }}