[Answered ]-Django OneToOne field in model's string representation

2👍

Your model is actually returning a model object in __unicode__ method instead it should return unicode string, you can do this:

def __unicode__(self):
    return unicode(self.user)

This will call User.__unicode__ which will return user.username. Thanks to Nathan Villaescusa on his answer.

Alternatively you can directly return the username of user in __unicode__ method:

def __unicode__(self):
    return self.user.username

Leave a comment