我可以将不同应用的多个模型添加到一个管理站点吗?

时间:2013-10-31 02:11:37

标签: python django django-models django-admin

我可以将不同应用的多个模型添加到一个管理网站吗?我想在管理面板的一个屋檐下看到两个应用程序(民意调查,新闻)模型。

目前在我的Django管理站点中显示了 NONE

我在admin.py文件中尝试

from tutorial.polls.models import Poll, Choice
from tutorial.news.models import Article, Reporter
from django.contrib import admin

admin.site.register(Poll)
admin.site.register(Choice)
admin.site.register(Article)
admin.site.register(Reporter)

我的目录结构:

(example)andi@MacBook-Pro-Andrzej:~/example/tutorial$ ls -lR
total 8
-rw-r--r--   1 andi  staff   251B 28 paź 11:53 manage.py
drwxr-xr-x  12 andi  staff   408B 31 paź 02:46 news/
drwxr-xr-x   9 andi  staff   306B 31 paź 02:46 polls/
drwxr-xr-x  12 andi  staff   408B 31 paź 03:06 tutorial/


    ./news:
    total 64
    -rw-r--r--  1 andi  staff     0B 31 paź 00:18 __init__.py
    -rw-r--r--  1 andi  staff   210B 31 paź 02:09 base.html
    -rw-r--r--  1 andi  staff   466B 31 paź 01:26 models.py
    -rw-r--r--  1 andi  staff   383B 31 paź 00:18 tests.py
    -rw-r--r--  1 andi  staff   277B 31 paź 02:08 views.py
    -rw-r--r--  1 andi  staff   329B 31 paź 01:53 year_archive.html

    ./polls:
    total 40
    -rw-r--r--  1 andi  staff     0B 31 paź 02:32 __init__.py
    -rw-r--r--  1 andi  staff   612B 31 paź 02:33 models.py
    -rw-r--r--  1 andi  staff   383B 31 paź 02:32 tests.py
    -rw-r--r--  1 andi  staff    26B 31 paź 02:32 views.py

    ./tutorial:
    total 72
    -rw-r--r--  1 andi  staff     0B 28 paź 11:53 __init__.py
    -rw-r--r--  1 andi  staff   244B 31 paź 03:06 admin.py
    -rw-r--r--  1 andi  staff   5,4K 31 paź 02:34 settings.py
    -rw-r--r--  1 andi  staff   752B 31 paź 02:36 urls.py
    -rw-r--r--  1 andi  staff   1,4K 28 paź 11:53 wsgi.py

1 个答案:

答案 0 :(得分:2)

欢迎使用Django编程!

轻松!在admin.pypolls/中创建news/,仅包含该应用所需的模型。

例如,polls/admin.py可能包含:

from models import Poll, Choice
from django.contrib import admin

admin.site.register(Poll)
admin.site.register(Choice)

应该工作得很好。

(我相信您当前的方法不起作用,因为pollsnews无法在tutorial/admin.py内找到,tutorial.polls.models可以&#39找不到它们 - polls/models/需要成为tutorial/的子目录才能发挥作用。否则你就会走上正轨 - 继续前进!:) )

相关问题