3

我不知道我做错了什么,但我无法将模型添加到我的管理员。

设置.py

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.admindocs',
'RM.cal',
'release',
'south',

)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.gzip.GZipMiddleware',
'django_notify.middleware.NotificationsMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',

)

TEMPLATE_CONTEXT_PROCESSORS = (
        global_settings.TEMPLATE_CONTEXT_PROCESSORS +
        ('django.core.context_processors.request','django.contrib.messages.context_processors.messages',)

 )

管理员.py

from cal.models import *
from django.contrib import admin
admin.site.register(Cos)

网址.py

 from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Example:
# (r'^RM/', include('RM.foo.urls')),
(r'^cal/', include('RM.cal.urls')),

# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
    {'document_root': 'C:/Users/sg0217297/Desktop/test/tkt_crmt/RM/media'}),

models.py 其新字段仅用于测试,但我可以将其添加到管理员;/

from django.db import models
from django.contrib import admin
class Cos(models.Model):
    name = models.CharField(max_length=400, blank= False , null = True)

    def __unicode__(self):
    return self.name

知道为什么吗?

感谢帮助

E:更新 urls.py

4

2 回答 2

1

你需要在你的类中定义一个 app_label,django 只为 models.py 看起来 1 级深度,所以:

class YourModel(models.Model):
    # whatever

    class Meta:
        app_label = 'cal'

您还可以在上面模块的init中导入第二级模型

于 2012-10-22T10:49:44.383 回答
0

尝试导入独立模型而不是 '*' :

from your_app.models import model1,model2
于 2012-10-22T11:44:42.973 回答