Author: lukeplant Date: 2011-06-01 16:17:40 -0700 (Wed, 01 Jun 2011) New Revision: 16312
Modified: django/trunk/django/contrib/admin/util.py django/trunk/tests/regressiontests/admin_views/tests.py Log: Fixed bug with `__str__` headers in admin changelist have a non-functioning sort URL Modified: django/trunk/django/contrib/admin/util.py =================================================================== --- django/trunk/django/contrib/admin/util.py 2011-06-01 22:09:50 UTC (rev 16311) +++ django/trunk/django/contrib/admin/util.py 2011-06-01 23:17:40 UTC (rev 16312) @@ -226,6 +226,12 @@ def label_for_field(name, model, model_admin=None, return_attr=False): + """ + Returns a sensible label for a field name. The name can be a callable or the + name of an object attributes, as well as a genuine fields. If return_attr is + True, the resolved attribute (which could be a callable) is also returned. + This will be None if (and only if) the name refers to a field. + """ attr = None try: field = model._meta.get_field_by_name(name)[0] @@ -236,8 +242,10 @@ except models.FieldDoesNotExist: if name == "__unicode__": label = force_unicode(model._meta.verbose_name) + attr = unicode elif name == "__str__": label = smart_str(model._meta.verbose_name) + attr = str else: if callable(name): attr = name Modified: django/trunk/tests/regressiontests/admin_views/tests.py =================================================================== --- django/trunk/tests/regressiontests/admin_views/tests.py 2011-06-01 22:09:50 UTC (rev 16311) +++ django/trunk/tests/regressiontests/admin_views/tests.py 2011-06-01 23:17:40 UTC (rev 16312) @@ -32,7 +32,7 @@ # local test models from models import (Article, BarAccount, CustomArticle, EmptyModel, - FooAccount, Gallery, ModelWithStringPrimaryKey, + FooAccount, Gallery, GalleryAdmin, ModelWithStringPrimaryKey, Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee, @@ -238,6 +238,17 @@ "Results of sorting on ModelAdmin method are out of order." ) + def testChangeListSortColumnsDefault(self): + # Need a model that has a list_display with '__str__' as only item. + # Sanity check for assumption made in following test. + self.assertEqual(list(GalleryAdmin.list_display), ['__str__']) + # A header corresponding to '__str__' should not be in an anchor + # for sorting. + g = Gallery.objects.create(name='gallery1') + response = self.client.get('/test_admin/%s/admin_views/gallery/' % self.urlbit, {}) + m = re.search('<th scope="col">\s*Gallery\s*</th>', response.content) + self.assertTrue(m is not None) + def testLimitedFilter(self): """Ensure admin changelist filters do not contain objects excluded via limit_choices_to. This also tests relation-spanning filters (e.g. 'color__value'). -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.