def init_with_context(self, context):
        """
        Please refer to
        :meth:`~admin_tools.menu.items.MenuItem.init_with_context`
        documentation from :class:`~admin_tools.menu.items.MenuItem` class.
        """
        items = self._visible_models(context['request'])
        apps = {}
        for model, perms in items:
            if not (perms['change'] or perms.get('view', False)):
                continue
            app_label = model._meta.app_label
            if app_label not in apps:
                apps[app_label] = {
                    'title':
                        django_apps.get_app_config(app_label).verbose_name,
                    'url': self._get_admin_app_list_url(model, context),
                    'models': []
                }
            apps[app_label]['models'].append({
                'title': model._meta.verbose_name_plural,
                'url': self._get_admin_change_url(model, context)
            })

        for app in sorted(apps.keys()):
            app_dict = apps[app]
            item = MenuItem(title=app_dict['title'], url=app_dict['url'])
            # sort model list alphabetically
            apps[app]['models'].sort(key=lambda x: x['title'])
            for model_dict in apps[app]['models']:
                item.children.append(MenuItem(**model_dict))
            self.children.append(item)
def init_with_context ( self , context ) : items = self . _visible_models ( context [ 'request' ] ) apps = { } for model , perms in items : if not ( perms [ 'change' ] or perms . get ( 'view' , False ) ) : continue app_label = model . _meta . app_label if app_label not in apps : apps [ app_label ] = { 'title' : django_apps . get_app_config ( app_label ) . verbose_name , 'url' : self . _get_admin_app_list_url ( model , context ) , 'models' : [ ] } apps [ app_label ] [ 'models' ] . append ( { 'title' : model . _meta . verbose_name_plural , 'url' : self . _get_admin_change_url ( model , context ) } ) for app in sorted ( apps . keys ( ) ) : app_dict = apps [ app ] item = MenuItem ( title = app_dict [ 'title' ] , url = app_dict [ 'url' ] ) apps [ app ] [ 'models' ] . sort ( key = lambda x : x [ 'title' ] ) for model_dict in apps [ app ] [ 'models' ] : item . children . append ( MenuItem ( ** model_dict ) ) self . children . append ( item )
Please refer to
        :meth:`~admin_tools.menu.items.MenuItem.init_with_context`
        documentation from :class:`~admin_tools.menu.items.MenuItem` class.