【发布时间】:2018-06-03 13:14:33
【问题描述】:
我的管理面板中有一个看似无害但非常琐碎的错误:
它错误地产生输出“Teacherss”(双 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 是从哪里来的,我该如何摆脱它!??
根据答案更新
更新:有趣的是,从下面的答案中注意到必须使用单数。但是我确实更改了我的代码,现在出现以下错误:
错误
在 admin.py 从 main.models 导入教师 导入错误:无法导入名称“教师”
admin.py 文件
from django.contrib import admin
from main.models import Teacher
# Register your models here.
admin.site.register(Teacher)
models.py
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 而不是 Teachers.models)。
感谢您的以下回答
【问题讨论】: