Code

Ticket #15221: 15221_m2m_filterspec_title.diff

File 15221_m2m_filterspec_title.diff, 1.1 KB (added by julien, 3 years ago)
Line 
1diff --git a/django/contrib/admin/filterspecs.py b/django/contrib/admin/filterspecs.py
2index eab5407..c2da791 100644
3--- a/django/contrib/admin/filterspecs.py
4+++ b/django/contrib/admin/filterspecs.py
5@@ -68,12 +68,10 @@ class RelatedFilterSpec(FilterSpec):
6             f, request, params, model, model_admin, field_path=field_path)
7 
8         other_model = get_model_from_relation(f)
9-        if isinstance(f, (models.ManyToManyField,
10-                          models.related.RelatedObject)):
11-            # no direct field on this model, get name from other model
12-            self.lookup_title = other_model._meta.verbose_name
13+        if hasattr(f, 'verbose_name') and f.verbose_name != u'':
14+            self.lookup_title = f.verbose_name
15         else:
16-            self.lookup_title = f.verbose_name # use field name
17+            self.lookup_title = other_model._meta.verbose_name
18         rel_name = other_model._meta.pk.name
19         self.lookup_kwarg = '%s__%s__exact' % (self.field_path, rel_name)
20         self.lookup_val = request.GET.get(self.lookup_kwarg, None)