Opened 11 years ago

Closed 11 years ago

#5233 closed (worksforme)

Getting a "TypeError; __str__ returned non-string (type Topic)" when trying to delete a item

Reported by: mgorree@… Owned by: Peter Baumgartner
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


There is no (visible, in terms of content) difference between a record that does delete
and one that errors-out. Seems to have something to do with foreign keys when a Topic has
votes; i get an error. If not that it works just fine.

My models:

class Topic(models.Model):
  id = models.AutoField(primary_key=True)
  date = models.DateTimeField()
  topic = models.CharField(maxlength=50)
  description = models.TextField()
  video_url = models.CharField(maxlength=50, blank=True)
  rating = models.IntegerField(blank=True)
  author = models.CharField(maxlength=25)
  email = models.CharField(maxlength=100)
  terms_accepted = models.BooleanField()
  key = models.SlugField()
  confirmed = models.BooleanField()
  remote_addr = models.CharField(maxlength=15, blank=True)
  reminder_sent = models.BooleanField()
  reminder_date = models.DateTimeField()

  class Admin:
    list_display = ('id', 'date', 'topic', 'rating', 'author', 'email', 'confirmed', 'video_url', 'reminder_sent', 'reminder_date')
    list_filter = ('date', 'confirmed')
    ordering = ('-rating',)
    search_fields = ('id', 'topic', 'description', 'author', 'email')

  def __str__(self):
    return self.topic

class Vote(models.Model):
    ('+', '+ 1'),
    ('-', '- 1')
  topic = models.ForeignKey(Topic)
  date = models.DateTimeField()
  email = models.CharField(maxlength=100)
  name = models.CharField(maxlength=25)
  type = models.CharField(maxlength=1, choices=TYPE_CHOICES)
  confirmed = models.BooleanField()
  key = models.SlugField(maxlength=32)
  reason = models.CharField(maxlength=255)
  reminder_sent = models.BooleanField()
  reminder_date = models.DateTimeField()

  class Admin:
    list_display = ('date', 'name', 'email', 'type', 'topic', 'confirmed')
    list_filter = ('date',)
    search_fields = ('name', 'email', 'topic')

  class Meta:
    unique_together = (('topic', 'email'),)

Using python 2.4.4

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/django/core/handlers/", line 77, in get_response
    response = callback(request, *callback_args, **callback_kwargs)

  File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/", line 55, in _checklogin
    return view_func(request, *args, **kwargs)

  File "/usr/lib/python2.4/site-packages/django/views/decorators/", line 39, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)

  File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/", line 512, in delete_stage
    _get_deleted_objects(deleted_objects, perms_needed, request.user, obj, opts, 1)

  File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/", line 456, in _get_deleted_objects
    nh(deleted_objects, current_depth, [u'%s: <a href="../../../../%s/%s/%s/">%s</a>' % \

  File "/usr/lib/python2.4/site-packages/django/utils/", line 122, in wrapper
    return func(*args, **kwargs)

  File "/usr/lib/python2.4/site-packages/django/utils/", line 30, in escape
    return force_unicode(html).replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;')

  File "/usr/lib/python2.4/site-packages/django/utils/", line 40, in force_unicode
    s = unicode(str(s), encoding, errors)

TypeError: __str__ returned non-string (type Topic)

Change History (2)

comment:1 Changed 11 years ago by anonymous

Owner: changed from nobody to Peter Baumgartner

comment:2 Changed 11 years ago by Peter Baumgartner

Resolution: worksforme
Status: newclosed

Unable to duplicate.

Probably unrelated, but

rating = models.IntegerField(blank=True)

should be

rating = models.IntegerField(blank=True, null=True)

if you are actually going to leave the rating field blank.

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