5👍
✅
As your error show:
TypeError __str__ returned non-string (type User)
The __str__
method should return a str
, and here, you are returning an object (User
).
You should return return self.user.__str__
instead (The str
representation of the user).
7👍
You need to refer to the specific field within ‘User’ you want to display.
Try:
def __str__(self):
return self.user.username
- [Django]-Django CONN_MAX_AGE setting error
- [Django]-How to combine select_related() and value()?
- [Django]-Django: 'User' object has no attribute 'user'
- [Django]-How to use django default group permission in django-graphene?
- [Django]-Adding a **kwarg to a class
2👍
you can only return string from __str__
not user which is an object.
def __str__(self):
return self.user.username
2👍
You need to show the attribute of the user that you wish to display
def __str__(self):
return self.user
should return any of the following (or similar)
return str(self.user)
return self.user.get_username()
return self.user.get_full_name()
- [Django]-Implement zeromq publisher in django with celery (Broker redis)
- [Django]-Django can't process non-ascii symbols
Source:stackexchange.com