使用自定义AdminSite时,我的应用程序不可见

时间:2010-09-09 11:52:43

标签: django django-admin

我的自定义AdminSite存在问题 - 我的应用程序在管理员索引处不可见,如果我键入适当的URL来查看其模型,则无法访问。我的问题与此非常相似:http://groups.google.com/group/django-users/browse_thread/thread/881feb7eef80853a但它是一种反向问题 - 捆绑的模型是可见的,但我的习惯不是。

我的项目名为magic,它有app。名为nullt

魔术/ admin.py:

from django.contrib.admin.sites import AdminSite
from django.contrib.auth.models import User, Group
from django.contrib.auth.admin import UserAdmin, GroupAdmin 

class MagicAdmin(AdminSite):
    pass

admin_site = MagicAdmin()

admin_site.register(Group, GroupAdmin)
admin_site.register(User, UserAdmin)

魔术/ nullt / admin.py

from magic.admin import admin_site
...
admin_site.register(Host, HostAdmin)
admin_site.register(Client, ClientAdmin)
...

魔术/ urls.py

from django.conf.urls.defaults import * #@UnusedWildImport
from magic.admin import admin_site

urlpatterns = patterns('',
    (r'^admin/', include(admin_site.urls)),
)

P.S。我正在使用安装了easy_install的Django 1.2.2和来自Ubuntu 10.04 x86_64的Python 2.6.5

1 个答案:

答案 0 :(得分:2)

默认情况下,新项目的urls.py中会注释以下两行:

from django.contrib import admin
admin.autodiscover()

来自django/contrib/admin/__init__.py

def autodiscover():
    """
    Auto-discover INSTALLED_APPS admin.py modules and fail silently when
    not present. This forces an import on them to register any admin bits they
    may want.
    """

即使您有自定义管理员,也可能需要进行此调用。