from django.db import connectiontables = connection.introspection.table_names()seen_models = connection.introspection.installed_models(tables)
如对manage.py的syncdb命令所示。
在下面的评论中,ThePhi说,在上述答案问世多年之后(我尚未测试):
from django.apps import apps from django.contrib import admin from django.contrib.admin.sites import AlreadyRegisteredapp_models = apps.get_app_config('my_app').get_models()
另一个用户评论说这也可行(也未经测试):
[ m._meta.db_table for c in apps.get_app_configs() for m in c.get_models() ]
另一个建议阅读此答案:
Django获取应用程序中的模型列表
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)