Ticket #8648: to_field.diff
File to_field.diff, 1.5 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/widgets.py
114 114 (related_url, url, name)) 115 115 output.append('<img src="%simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % settings.ADMIN_MEDIA_PREFIX) 116 116 if value: 117 # if to_field for this relation is not the primary key field, transform value to 118 # target's pk value so selected choice is correct in the widget display 119 if hasattr(self.rel, 'field_name') and self.rel.field_name != self.rel.to._meta.pk.attname: 120 value = self.rel.to._default_manager.get(**{self.rel.field_name: value}).pk 117 121 output.append(self.label_for_value(value)) 118 122 return mark_safe(u''.join(output)) 119 123 … … 184 188 185 189 def render(self, name, value, *args, **kwargs): 186 190 rel_to = self.rel.to 191 # if to_field for this relation is not the primary key field, transform value to 192 # target's pk value so selected choice is correct in the widget display 193 if value and self.rel.field_name != rel_to._meta.pk.attname: 194 value = rel_to._default_manager.get(**{self.rel.field_name: value}).pk 187 195 related_url = '../../../%s/%s/' % (rel_to._meta.app_label, rel_to._meta.object_name.lower()) 188 196 self.widget.choices = self.choices 189 197 output = [self.widget.render(name, value, *args, **kwargs)]