我的代码曾经在 Django 1.3 中工作,但在更新到 Django 1.4 之后它不再工作了。这个想法是为 django-admin-tools 构建一个 MenuItem,其中包含来自应用程序的模型列表。
from admin_tools.utils import AppListElementMixin
from app import models as my_models
class CustomMenu(Menu):
def init_with_context(self, context):
app_list=AppListElementMixin()
'''ERROR not working after upgrade to django 1.4, returns empty list'''
all_models = get_models(app_mod=my_models)
''''''
dict_models = {}
for model in all_models:
dict_models[model.__name__] = items.MenuItem(
title=model._meta.verbose_name_plural,
url=app_list._get_admin_change_url(model, context)
)