django admin中显示Django模型字段

问题描述 投票:0回答:1

在我的django管理员模型(配置文件)中,我无法看到在django模型中声明的StudentID字段。models.py

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    StudentID = models.AutoField(primary_key=True, verbose_name='SID')
    Branch = models.CharField(max_length=255, choices=Departments, default="CSE")
    YearOfStudy = models.IntegerField(default=1)
    ContactNumber = PhoneField(help_text='Contact phone number')
    image = models.ImageField(default='default.jpeg', upload_to='profile_pics', blank=True)
    parentsContactNumber = PhoneField(help_text="Parent's phone number", blank=True)

    def __str__(self):
        return f'{self.user.username} Profile'

enter image description here

python django django-admin
1个回答
-1
投票

要在管理页面中反映您的StudentID,您必须在str函数中将其返回

    def __str__(self): 
    return self.StudentID
© www.soinside.com 2019 - 2024. All rights reserved.