更新时间:2023-02-26 10:27:47
from django.db import connection
tables = connection.introspection.table_names()
seen_models = connection.introspection.installed_models(tables)
在manage.py的syncdb命令中看到.
As seen in the syncdb command for manage.py.
在上面的答案问世多年之后,在下面的评论中, ThePhi 说(我没有测试过):
In a comment below, years after the answer above, ThePhi says (I haven't tested it):
from django.apps import apps
from django.contrib import admin
from django.contrib.admin.sites import AlreadyRegistered
app_models = apps.get_app_config('my_app').get_models()