答案 0 :(得分:1)
将以下代码放入django app的admin.py文件
中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()
for model in app_models:
try:
admin.site.register(model)
except AlreadyRegistered:
pass
参考:https://docs.djangoproject.com/en/2.0/ref/contrib/admin/和Register every table/class from an app in the Django admin page