简体   繁体   English

在Django的管理控制中,我无法添加模型

[英]In the admin control of django I can`t add my models

I`m trying to add my models ( the models are named "Question" and "Answer" respectively allocated in models.py archive) to the Django admin control center. 我正在尝试将我的模型(分别在models.py档案中分配的模型分别命名为“ Question”和“ Answer”)添加到Django管理控制中心。 So, to do that I make the following the settings in the following archives: 因此,为此,我在以下档案中进行了以下设置:

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admindocs',
'questionsandanswers',
)

After that I synchronize the database again to commit the change. 之后,我再次同步数据库以提交更改。

python manage.py syncdb

In the urls.py file I have the following setting: 在urls.py文件中,我有以下设置:

from django.conf.urls import patterns, include, include, url
from django.contrib import admin
admin.autodiscover()


urlpatterns = patterns('',
    url(r'^$', 'miprimerproyecto.views.home', name='home'),
    url(r'^blog/', include('blog.urls')),
                ................
    url(r'^admin/', include(admin.site.urls)),
)

The admin.py file allocated inside of the models folders, has the following configuration: 在models文件夹内分配的admin.py文件具有以下配置:

from django.contrib import admin 
from questionsandanswers.models import Question, Answer

admin.site.register(Question) 
admin.site.register(Answer)

After the I restart the server again: 之后,我再次重新启动服务器:

python manage.py runserver

But the when I enter in the admin console I don' t see the models on the board. 但是当我进入管理控制台时,我在板上看不到模型。

I would be very grateful If somebody could help me to solve this issue. 如果有人可以帮助我解决这个问题,我将不胜感激。

You probably don't have permissions set for those models yet. 您可能尚未为这些模型设置权限。 You can check that by logging in with a superuser account, which has all permissions. 您可以使用具有所有权限的超级用户帐户登录来进行检查。 If your superuser account shows the admin options for the new models but your regular account doesn't, that confirms that your regular account lacks permissions for those models. 如果您的超级用户帐户显示了新模型的管理员选项,但您的普通帐户没有,则表明您的普通帐户没有这些模型的权限。 You can use the superuser account to add permissions to a group or directly to the account you'd like to use in the auth admin. 您可以使用超级用户帐户向组添加权限,也可以直接向您要在auth管理员中使用的帐户添加权限。

与其运行python manage.py syncdb python manage.py makemigrations尝试运行python manage.py syncdb python manage.py makemigrations ,然后运行python manage.py migrate python manage.py makemigrations ,然后启动服务器并再次检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM