Ticket #15221: 15221_m2m_filterspec_title.3.diff

File 15221_m2m_filterspec_title.3.diff, 5.0 KB (added by dmclain, 4 years ago)

updated patch to match up against trunk

  • django/contrib/admin/filters.py

    diff --git a/django/contrib/admin/filters.py b/django/contrib/admin/filters.py
    index c1fc979..341b46e 100644
    a b class RelatedFieldListFilter(FieldListFilter): 
    148148            field, request, params, model, model_admin, field_path)
    149149
    150150        other_model = get_model_from_relation(field)
    151         if isinstance(field, (models.ManyToManyField,
    152                           models.related.RelatedObject)):
    153             # no direct field on this model, get name from other model
    154             self.lookup_title = other_model._meta.verbose_name
     151        if hasattr(field, 'verbose_name') and field.verbose_name != u'':
     152            self.lookup_title = field.verbose_name
    155153        else:
    156             self.lookup_title = field.verbose_name # use field name
     154            self.lookup_title = other_model._meta.verbose_name
    157155        rel_name = other_model._meta.pk.name
    158156        self.lookup_kwarg = '%s__%s__exact' % (self.field_path, rel_name)
    159157        self.lookup_kwarg_isnull = '%s__isnull' % (self.field_path)
  • tests/regressiontests/admin_filters/models.py

    diff --git a/tests/regressiontests/admin_filters/models.py b/tests/regressiontests/admin_filters/models.py
    index 80d54c7..beb0089 100644
    a b from django.contrib.auth.models import User 
    44class Book(models.Model):
    55    title = models.CharField(max_length=50)
    66    year = models.PositiveIntegerField(null=True, blank=True)
    7     author = models.ForeignKey(User, related_name='books_authored', blank=True, null=True)
    8     contributors = models.ManyToManyField(User, related_name='books_contributed', blank=True, null=True)
     7    author = models.ForeignKey(User, verbose_name='author_verbose', related_name='books_authored', blank=True, null=True)
     8    contributors = models.ManyToManyField(User, verbose_name='contributors_verbose', related_name='books_contributed', blank=True, null=True)
    99    is_best_seller = models.NullBooleanField(default=0)
    1010    date_registered = models.DateField(null=True)
    1111
  • tests/regressiontests/admin_filters/tests.py

    diff --git a/tests/regressiontests/admin_filters/tests.py b/tests/regressiontests/admin_filters/tests.py
    index 7717984..c1c0b52 100644
    a b class ListFiltersTests(TestCase): 
    232232
    233233        # Make sure the last choice is None and is selected
    234234        filterspec = changelist.get_filters(request)[0][1]
    235         self.assertEqual(force_unicode(filterspec.title), u'author')
     235        self.assertEquals(force_unicode(filterspec.title), u'author_verbose')
    236236        choices = list(filterspec.choices(changelist))
    237237        self.assertEqual(choices[-1]['selected'], True)
    238238        self.assertEqual(choices[-1]['query_string'], '?author__isnull=True')
    class ListFiltersTests(TestCase): 
    242242
    243243        # Make sure the correct choice is selected
    244244        filterspec = changelist.get_filters(request)[0][1]
    245         self.assertEqual(force_unicode(filterspec.title), u'author')
     245        self.assertEquals(force_unicode(filterspec.title), u'author_verbose')
    246246        # order of choices depends on User model, which has no order
    247247        choice = select_by(filterspec.choices(changelist), "display", "alfred")
    248248        self.assertEqual(choice['selected'], True)
    class ListFiltersTests(TestCase): 
    260260
    261261        # Make sure the last choice is None and is selected
    262262        filterspec = changelist.get_filters(request)[0][2]
    263         self.assertEqual(force_unicode(filterspec.title), u'user')
     263        self.assertEquals(force_unicode(filterspec.title), u'contributors_verbose')
    264264        choices = list(filterspec.choices(changelist))
    265265        self.assertEqual(choices[-1]['selected'], True)
    266266        self.assertEqual(choices[-1]['query_string'], '?contributors__isnull=True')
    class ListFiltersTests(TestCase): 
    270270
    271271        # Make sure the correct choice is selected
    272272        filterspec = changelist.get_filters(request)[0][2]
    273         self.assertEqual(force_unicode(filterspec.title), u'user')
     273        self.assertEquals(force_unicode(filterspec.title), u'contributors_verbose')
    274274        choice = select_by(filterspec.choices(changelist), "display", "bob")
    275275        self.assertEqual(choice['selected'], True)
    276276        self.assertEqual(choice['query_string'], '?contributors__id__exact=%d' % self.bob.pk)
    class ListFiltersTests(TestCase): 
    471471        self.assertEqual(choices[3]['query_string'], '?publication-decade=the+00s&author__id__exact=%s' % self.alfred.pk)
    472472
    473473        filterspec = changelist.get_filters(request)[0][0]
    474         self.assertEqual(force_unicode(filterspec.title), u'author')
     474        self.assertEquals(force_unicode(filterspec.title), u'author_verbose')
    475475        choice = select_by(filterspec.choices(changelist), "display", "alfred")
    476476        self.assertEqual(choice['selected'], True)
    477477        self.assertEqual(choice['query_string'], '?publication-decade=the+00s&author__id__exact=%s' % self.alfred.pk)
Back to Top