链接到 admin.py 的 Django 管理面板显示错误?
Django admin panel display error linked to admin.py?
我的管理面板中有一个看似无害但非常烦人的错误:
它错误地产生了输出 "Teacherss"(double 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)
知道为什么会在管理面板中生成这个吗?
主要
老师 Add/Change
double ss 是从哪里来的,我该如何摆脱它!??
根据回答更新
更新:有趣的是从下面的答案中注意到必须使用单数。但是我确实更改了我的代码,现在出现以下错误:
错误
在admin.py
来自 main.models 导入老师
导入错误:无法导入名称 'Teacher'
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)。
感谢您的以下回答
Django 管理员自动添加一个 "s" 使模型成为复数。将您的模型设为 Teacher
可能更有意义。否则你可以告诉管理员你想要的复数形式是什么:
class Teachers(models.Model):
class Meta:
verbose_name_plural = "teachers"
email=models.CharField(max_length=250)
...
默认情况下,Django 希望您的模型有一个单数名称,即 Teacher
。它还默认将 s
附加到您的模型名称以在管理员中显示。这可以从 inside your model itself.
配置
我的管理面板中有一个看似无害但非常烦人的错误:
它错误地产生了输出 "Teacherss"(double 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)
知道为什么会在管理面板中生成这个吗?
主要 老师 Add/Change
double ss 是从哪里来的,我该如何摆脱它!??
根据回答更新
更新:有趣的是从下面的答案中注意到必须使用单数。但是我确实更改了我的代码,现在出现以下错误:
错误
在admin.py 来自 main.models 导入老师 导入错误:无法导入名称 'Teacher'
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)。
感谢您的以下回答
Django 管理员自动添加一个 "s" 使模型成为复数。将您的模型设为 Teacher
可能更有意义。否则你可以告诉管理员你想要的复数形式是什么:
class Teachers(models.Model):
class Meta:
verbose_name_plural = "teachers"
email=models.CharField(max_length=250)
...
默认情况下,Django 希望您的模型有一个单数名称,即 Teacher
。它还默认将 s
附加到您的模型名称以在管理员中显示。这可以从 inside your model itself.