Search code examples
djangounicodemodeladmin

Django - Display "Model Object" in the admin page instead of Object title


As displayed in the image it displays "Lecture Object" instead of the Lecture's title. As I've understood it, unicode should take care of this, but it doesn't seem to here.

Here is my unicode method:

def __unicode__(self):
    return self.title

Solution

  • To display a custom string as your Model's object representation, you should:

    In Python 2.x

    def __unicode__(self):
        return self.some_attr  # What you want to show
    

    In Python 3.x

    def __str__(self):
        return self.some_attr  # What you want to show