diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
index fb5acb5..d9f2e0b 100644
a
|
b
|
class ForeignKeyRawIdWidget(forms.TextInput):
|
148 | 148 | |
149 | 149 | def label_for_value(self, value): |
150 | 150 | key = self.rel.get_related_field().name |
151 | | obj = self.rel.to._default_manager.get(**{key: value}) |
152 | | return ' <strong>%s</strong>' % escape(truncate_words(obj, 14)) |
| 151 | |
| 152 | # Our value will not be valid if the user enters incorrect data (i.e. |
| 153 | # non-existent pk or a non-integer value). Normal form validation will |
| 154 | # handle this as long as we don't raise an exception here: |
| 155 | try: |
| 156 | obj = self.rel.to._default_manager.get(**{key: value}) |
| 157 | return ' <strong>%s</strong>' % escape(truncate_words(obj, 14)) |
| 158 | except (ValueError, self.rel.to.DoesNotExist): |
| 159 | return "" |
153 | 160 | |
154 | 161 | class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): |
155 | 162 | """ |