
In Django I made an entity called User in Models, when I made it visible in the Admin page it shows it only as User Object instead of by the id or name, how can I change this?
How can I change this to something intuitive ? Like the ID or the Name of the user ?
models.py shows:
class User(models.Model):
user_id = models.CharField(primary_key=True, max_length=200)
name = models.CharField(max_length=200)
phone_number = models.CharField(max_length=200)
user_password = models.CharField(max_length=20)
email = models.CharField(max_length=200)
category = ( ('A','First AC'), ('B','Second AC'), ('C','Third AC'), ('D','Sleeper') )
Additionally how come the choices in category do not appear on the Add User screen ?

The admin.py for this app[named 'data'] has:
from django.contrib import admin
from data.models import User
admin.site.register(User)
Include a __str__ method in your model that returns the string that you want to show:
class User(models.Model):
user_id = models.CharField(primary_key=True, max_length=200)
name = models.CharField(max_length=200)
phone_number = models.CharField(max_length=200)
user_password = models.CharField(max_length=20)
email = models.CharField(max_length=200)
category = ( ('A','First AC'), ('B','Second AC'), ('C','Third AC'), ('D','Sleeper') )
def __str__(self):
return '{}'.format(self.user_id)
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