-
Notifications
You must be signed in to change notification settings - Fork 31
[DJ08] Model does not define __str__ method
Rocio Aramberri edited this page May 23, 2020
·
5 revisions
It is recommended to define an __str__
method within a Model. The __str__
method is used whenever str(model_object)
is called. Django uses the str()
method as the display value on the Django Admin, otherwise the Admin will only show: [object Object]
as the display value.
class Post:
title = models.CharField()
class Post:
title = models.CharField()
def __str__(self):
return f'{self.title}'
https://docs.djangoproject.com/en/3.0/ref/models/instances/#django.db.models.Model.__str__