2012-10-10 2 views
2

Django 1.3에서 작동하는 데 사용되는 코드가 있지만 Django 1.4로 업데이트 한 후 더 이상 사용하지 않습니다. 아이디어는 django-admin-tools의 MenuItem을 앱의 모델 목록과 함께 빌드하는 것입니다. 당신의 목표는 각 모델에 대한 메뉴 항목을 추가하는 경우django.db.models django1.4에서 빈 목록을 반환하는 get_models

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) 
              ) 

답변

2

시도는 다른 그룹에서이

from django.db.models import get_models, get_app 

내가 그것을 사용이

all_models = get_models(app_mod=get_app('app')) 
0

, 당신은 시도 할 수 있습니다 :

from django.core.urlresolvers import reverse 
from django.utils.translation import ugettext_lazy as _ 

from admin_tools.menu import items, Menu 

class CustomMenu(Menu): 
    def __init__(self, **kwargs): 
     Menu.__init__(self, **kwargs) 
     self.children += [ 
      # Other items that are in the menu eg "items.Bookmarks()," go here 
      items.AppList(
       _('Name of the submenu'), # Your own choosing 
       models=('app.models.*',) # Assuming your django app is called "app" 
      ) 
     ] 

    def init_with_context(self, context): 
     return super(CustomMenu, self).init_with_context(context) 

이것은 내가 내 프로젝트 중 하나에서 작업 한 것입니다.

+0

,하지만 난이 그룹에 시도 된 모델을 settings.py INSTALLED_APPS 으로 '응용 프로그램을'추가 이름을 지정하고 메뉴에서 앱 단계를 제거하십시오. 왜 내가 이해할 수없는 것은 get_models이 Django-1.4로 업그레이드 한 후에 빈 모델을 반환하는 이유이다. – pedrovgp

관련 문제