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
The __str__ method just tells Django what to print when it needs to print out an instance of the any model. It is also what lets your admin panel, go from this. Note: how objects are just plainly numbered.
To change the admin site header text, login page, and the HTML title tag of our bookstore's instead, add the following code in urls.py . The site_header changes the Django administration text which appears on the login page and the admin site. The site_title changes the text added to the <title> of every admin page.
To do so, you will have to change the project's settings.py . Find the TEMPLATES section and modify accordingly. To override the default template you first need to access the template you want to modify from the django/contrib/admin/templates/admin directory.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With