问题
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
回答1:
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
来源:https://stackoverflow.com/questions/33784129/django-display-model-object-in-the-admin-page-instead-of-object-title