Django模型为admin,整数字段和文本字段在admin部分不可见

时间:2018-06-29 11:10:11

标签: django django-models django-admin

class Student(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    father_name = models.CharField(max_length=60)
    age = models.SmallIntegerField
    created = models.DateTimeField(auto_now=False, auto_now_add=True)
    modified = models.DateTimeField(auto_now=True, auto_now_add=False)
    address = models.TextField
    email = models.EmailField(default="")
    id = models.AutoField
    std = models.SmallIntegerField
    remarks = models.TextField

我创建了一个名为Student的模型,并将其添加到Django admin中并进行了迁移。迁移没有问题。当我尝试通过管理页面添加新学生时,我只得到以下字段,如何在UI中获取如age这样的整数字段? enter image description here

1 个答案:

答案 0 :(得分:1)

当您要在Django模型中创建字段(相当于表中的列)时,您需要调用该特定字段的函数。

在这里,您仅指的是特定功能,而不是实际调用它们。

因此解决方案:

class Student(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    father_name = models.CharField(max_length=60)
    age = models.SmallIntegerField()
    created = models.DateTimeField(auto_now=False, auto_now_add=True)
    modified = models.DateTimeField(auto_now=True, auto_now_add=False)
    address = models.TextField()
    email = models.EmailField(default="")
    id = models.AutoField()
    std = models.SmallIntegerField()
    remarks = models.TextField()