0

I had accidentally misplaced the tab indentation of two def __unicode__(self): methods in my models.py. I.e. for two models, I had done the following:

class Notification(models.model):
     recipient = models.OneToOneField(User)
     timestamp = models.DateTimeField()

def __unicode__(self):
          return "%s recieved a notification" % self.recipient

The def statement was at the same level as the class, the return statement was indented as if the method header was properly indented.

I corrected it and pushed to production (a Postgres setup w/ Heroku). If I access the admin panel locally (on SQLite), these data models populate correctly now. But if I try to access the admin panel of my live app, I get a 500 response and through NewRelic, I find that:

exceptions:UnicodeDecodeError /django.contrib.admin.options:changelist_view exceptions:UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 68: ordinal not in range(128)

I looked at similar questions such as these, but they don't seem to apply to my case. What is django.contrib.admin.options:changelist_view, and what exactly is that error trying to tell me. I need help in resolving this guys.

p.s. this pertains to a legacy project using Django 1.5 and Python 2.7

Community
  • 1
  • 1
Hassan Baig
  • 15,055
  • 27
  • 102
  • 205

1 Answers1

1

You should be returning a Unicode object not a string object.

Assuming self.recepient is a Unicode already, do:

return u"%s recieved a notification" % self.recipient

Note the u

Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100