Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#12841 closed (duplicate)

In admin options class, blank short_description causes "string index out of range" exception

Reported by: gregplaysguitar Owned by: nobody
Component: contrib.admin Version: 1.2-beta
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:



from models import MyModel
from django.contrib import admin

class MyModelAdmin(admin.ModelAdmin):
    list_display = ('name', 'my_custom_method', )
    def my_custom_method(self, instance):
        return 'custom text'

    my_custom_method.short_description = '', MyModelAdmin)


This admin classes changelist seems to throw a TemplateSyntaxError when trying to prettify the short description (which I'd have thought shouldn't really be happening; the point of short description in this context is to customise the column header, which by default is created by prettifying the function name)

The full traceback is

Original Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/", line 72, in render_node
    result = node.render(context)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/", line 945, in render
    dict = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/templatetags/", line 194, in result_list
    'result_headers': list(result_headers(cl)),
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/templatetags/", line 91, in result_headers
    header = pretty_name(header)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/forms/", line 22, in pretty_name
    name = name[0].upper() + name[1:]
IndexError: string index out of range

Attachments (1)

12841.patch (432 bytes) - added by ales_zoulek 6 years ago.
Simple patch

Download all attachments as: .zip

Change History (5)

comment:1 Changed 6 years ago by Alex

  • Component changed from Uncategorized to django.contrib.admin
  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 6 years ago by ales_zoulek

Simple patch

comment:2 Changed 6 years ago by ales_zoulek

I've attached just a simple patch that uses string's method capitalize() instead.

comment:3 Changed 6 years ago by yedpodtrzitko

  • Resolution set to duplicate
  • Status changed from new to closed

duplicate of #12434

comment:4 Changed 5 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top