Opened 17 years ago
Closed 17 years ago
#4463 closed (invalid)
Admin crashed if None returned by __unicode__ and list_display not defined
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | contrib.admin | Version: | other branch |
Severity: | Keywords: | unicode unicode-branch admin | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Subj.
Testcase:
name = models.CharField(verbose_name=u'name', maxlength=255, null=True, blank=True) def __unicode__(self): return self.name
Traceback:
Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render_node 764. result = node.render(context) File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render 909. dict = func(*args) File "/usr/lib/python2.5/site-packages/django/contrib/admin/templatetags/admin_list.py" in result_list 206. 'results': list(results(cl))} File "/usr/lib/python2.5/site-packages/django/contrib/admin/templatetags/admin_list.py" in results 201. yield list(items_for_result(cl,res)) File "/usr/lib/python2.5/site-packages/django/contrib/admin/templatetags/admin_list.py" in items_for_result 137. attr = attr() File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in __str__ 91. return force_unicode(self).encode('utf-8') File "/usr/lib/python2.5/site-packages/django/utils/encoding.py" in force_unicode 38. s = unicode(s) TypeError at /admin/blog/contributor/ coercing to Unicode: need string or buffer, NoneType found
Change History (2)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
(I'm guessing this is on the unicode branch.)
If your __unicode__
method is returning None, that's a bug in your code. You must always return a unicode object from ___unicode___
and a str object from __str__
. That's a Python requirement.
Try returning unicode(self.name).
Note:
See TracTickets
for help on using tickets.
P.S.: Crash at draw list-of-objects page...
P.P.S: Also admin crashed when draw breadcrumbs on edit-of-object page: