Ticket #7028: improved-raw-id-admin-django-1.0.1.diff
File improved-raw-id-admin-django-1.0.1.diff, 3.7 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/media/js/admin/RelatedObjectLookups.js
41 41 return false; 42 42 } 43 43 44 function dismissRelatedLookupPopup(win, chosenId ) {44 function dismissRelatedLookupPopup(win, chosenId, chosenName) { 45 45 var name = windowname_to_id(win.name); 46 46 var elem = document.getElementById(name); 47 var nameElem = document.getElementById("view_lookup_" + name); 48 47 49 if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) { 48 50 elem.value += ',' + chosenId; 49 51 } else { 50 52 document.getElementById(name).value = chosenId; 51 53 } 54 if(nameElem) { 55 nameElem.innerHTML = chosenName; 56 } 52 57 win.close(); 53 58 } 54 59 -
django/contrib/admin/templatetags/admin_list.py
223 223 else: 224 224 attr = pk 225 225 result_id = repr(force_unicode(getattr(result, attr)))[1:] 226 result_name = repr(escape(force_unicode(result).replace("'", '&prime')))[1:] 226 227 yield mark_safe(u'<%s%s><a href="%s"%s>%s</a></%s>' % \ 227 (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s ); return false;"' % result_id or ''), conditional_escape(result_repr), table_tag))228 (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s, %s); return false;"' % (result_id or '', result_name)), conditional_escape(result_repr), table_tag)) 228 229 else: 229 230 yield mark_safe(u'<td%s>%s</td>' % (row_class, conditional_escape(result_repr))) 230 231 -
django/contrib/admin/widgets.py
121 121 output.append('<a href="%s%s" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> ' % \ 122 122 (related_url, url, name)) 123 123 output.append('<img src="%simg/admin/selector-search.gif" width="16" height="16" alt="%s" /></a>' % (settings.ADMIN_MEDIA_PREFIX, _('Lookup'))) 124 if value: 125 output.append(self.label_for_value(value)) 124 #if value: 125 # output.append(self.label_for_value(value)) 126 output.append(self.label_for_value(value, "id_%s" % name)) 126 127 return mark_safe(u''.join(output)) 127 128 128 129 def base_url_parameters(self): … … 149 150 obj = self.rel.to._default_manager.get(**{key: value}) 150 151 return ' <strong>%s</strong>' % truncate_words(obj, 14) 151 152 153 def label_for_value(self, value, name=''): 154 # Placeholder used to display description during insertion 155 if value: 156 key = self.rel.get_related_field().name 157 obj = self.rel.to.objects.get(**{key: value}) 158 else: 159 obj = '' 160 return ' <strong id="view_lookup_%s">%s</strong>' % \ 161 (name, truncate_words(obj, 14)) 162 152 163 class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): 153 164 """ 154 165 A Widget for displaying ManyToMany ids in the "raw_id" interface rather than … … 168 179 def url_parameters(self): 169 180 return self.base_url_parameters() 170 181 171 def label_for_value(self, value ):182 def label_for_value(self, value, nome=''): 172 183 return '' 173 184 174 185 def value_from_datadict(self, data, files, name):