Change all __unicode__ methods into __str__

In Python 3, the __str__() method is called for string representation of your models rather than the awkward sounding __unicode__() method. This is one of the most evident ways of identifying Python 3 ported code:

Python 2

Python 3

class Person(models.Model):   
    name = models.TextField()       def __unicode__(self):   
        return self.name   
class Person(models.Model):    name = models.TextField()    def __str__(self):        return self.name

 

This reflects the difference in the way Python 3 treats strings. In Python 2, the human readable representation of a class can be returned by __str__() (bytes) or __unicode__() (text). However, in Python 3, the readable representation is simply returned by __str__() (text). ...

Get Django Design Patterns and Best Practices - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.