Django管理面板显示错误链接到admin.py?

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

我的管理面板中有一个看似无害但非常琐碎的错误:

它错误地产生输出“教师”(双ss),我不明白为什么这会从我的代码中发生:

所以教师应用中的models.py是:

class Teachers(models.Model):
    #this is what an album is going to be made of
    email=models.CharField(max_length=250)
    school_name=models.CharField(max_length=500)
    password=models.CharField(max_length=100)
    class_name=models.CharField(max_length=100)

admin.py文件包含:

from django.contrib import admin
from main.models import Teachers 
# Register your models here.
admin.site.register(Teachers)

知道为什么在管理面板中生成这个?

主要教师添加/更改

双ss来自哪里,如何摆脱它!??

基于答案的更新

更新:有趣的是从下面的答案中注意到必须使用单数。但我确实更改了我的代码,现在出现以下错误:

错误

在main.models的admin.py中导入教师导入错误:无法导入名称'教师'

admin.py文件

from django.contrib import admin
from main.models import Teacher
# Register your models here.
admin.site.register(Teacher)

models.朋友

from django.db import models

# Create your models here.
class Teacher(models.Model):
    #this is what an album is going to be made of
    email=models.CharField(max_length=250)
    school_name=models.CharField(max_length=500)
    password=models.CharField(max_length=100)
    class_name=models.CharField(max_length=100)

                #You need this for meta data purposes. This allows you to reference the post (otherwise it will just print the object which doesn't mean much)
                #You need this for meta data purposes. This allows you to reference the post (otherwise it will just print the object which doesn't mean much)

......问题解决了我没有在导入模型中调用应用程序(main.models已经编写而不是teacher.models)。

谢谢你的以下答案

django admin models
2个回答
2
投票

默认情况下,Django希望您的模型具有单数名称,即Teacher。默认情况下,它还会将s附加到您的模型名称,以便在管理员中显示它。这可以从inside your model itself配置。


1
投票

Django管理员自动添加“s”以使模型复数。改为制作你的模型Teacher可能是有意义的。否则,您可以告诉管理员您想要复数形式:

class Teachers(models.Model):
    class Meta:
       verbose_name_plural = "teachers"
    email=models.CharField(max_length=250)
    ...
© www.soinside.com 2019 - 2024. All rights reserved.