Ticket #2569: adminforeign.3.diff

File adminforeign.3.diff, 5.1 KB (added by Joel Heenan <joelh-django@…>, 9 years ago)

Improvements

  • django/db/models/fields/related.py

     
    566566
    567567        self.db_index = True
    568568
     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
    569574    def get_attname(self):
    570575        return '%s_id' % self.name
    571576
  • django/contrib/admin/media/js/admin/RelatedObjectLookups.js

     
    5555    }
    5656    win.close();
    5757}
     58
     59function 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
     73function 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

     
    130130
    131131        if field.rel:
    132132            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
    133137
    134138    def original_value(self):
    135139        if self.original:
     
    343347            LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, str(new_object), CHANGE, change_message)
    344348
    345349            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)
    346354            if request.POST.has_key("_continue"):
    347355                request.user.message_set.create(message=msg + ' ' + _("You may edit it again below."))
    348356                if request.REQUEST.has_key('_popup'):
  • django/contrib/admin/templates/widget/one_to_one.html

     
     1{% load admin_modify adminmedia %}
    12{% if add %}{% include "widget/foreign.html" %}{% endif %}
    2 {% if change %}{% if bound_field.existing_display %}&nbsp;<strong>{{ bound_field.existing_display|truncatewords:"14"|escape }}</strong>{% endif %}{% endif %}
     3{% if change %}
     4{% if bound_field.rel_to_pk %}&nbsp;<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

     
    88    {% endif %}
    99{% else %}
    1010{% 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 %}
    1316{% if change %}
    1417    {% if bound_field.field.primary_key %}
    1518        {{ bound_field.original_value }}
Back to Top