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

Python 我可以将不同应用程序中的多个模型添加到一个管理站点吗?,python,django,django-models,django-admin,Python,Django,Django Models,Django Admin,我可以将不同应用程序中的多个模型添加到一个管理站点吗?我想看到,例如,两个应用程序(民意测验,新闻)模型下的一个屋顶的管理面板 目前,在我的Django管理站点中,未显示任何型号 我在admin.py文件中尝试 from tutorial.polls.models import Poll, Choice from tutorial.news.models import Article, Reporter from django.contrib import admin admin.site.r

我可以将不同应用程序中的多个模型添加到一个管理站点吗?我想看到,例如,两个应用程序(民意测验,新闻)模型下的一个屋顶的管理面板

目前,在我的Django管理站点中,未显示任何型号

我在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

欢迎来到Django编程

轻松点!在
polls/
news/
中创建一个
admin.py
,只包含该应用程序所需的型号

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

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

admin.site.register(Poll)
admin.site.register(Choice)
那应该行得通


(我认为您当前的方法不起作用,因为从
tutorial/admin.py
tutorial.polls.models
中无法访问
polls
models/
必须是
tutorial/
的子目录,否则您将无法找到它们“我们走对了--继续走!:)

谢谢。我刚刚在每个应用程序中创建了admin.py。我没想到django会自动合并它,但神奇的事情发生了。