3👍
✅
You should use __str__
instead of user in list_display:
list_display=['__str__']
Otherwise you tell django to show user
field. And since User
model doen’t have overrided __str__
method you see user’s id.
Also you can just remove list_display
attribute. In this case __str__
will be used by default.
1👍
The list_display
–(Django doc) support callable methods too. So, define a user(...)
method on Model admin as,
class OnlineUsersAdmin(admin.ModelAdmin):
# a list of displayed columns name.
list_display = ['user']
def user(self, instance):
return instance.__str__()
👤JPG
- [Django]-Including static js files in django 1.7
- [Django]-Sprinkling VueJs components into Django templates
0👍
Here, inside return you can return only str + str, not str + int. So, you have to convert every int to str
from django.db import models
# Create your models here.
class Fabonacci(models.Model):
numstr = models.IntegerField()
terms = models.CharField(max_length=500)
def __str__(self):
return "The first " + str(self.numstr) + " terms in fibonacci series : " + self.terms
- [Django]-Django Forms – Many to Many relationships
- [Django]-Django-CMS AppHooks with conflicting urls?
- [Django]-Django objects.filter with 2 conditions for the same keyword where either of them match
- [Django]-How to install python3 and Django using userdata in AWS EC2 with aws cli boto3
Source:stackexchange.com