Pergunta

I want to add a custom link to a ModelList group on django-admin-tools. I tried that but it didn't show the link. What am I missing ?

class CustomIndexDashboard(Dashboard):
    columns = 2

    def __init__(self, **kwargs):
        Dashboard.__init__(self, **kwargs)

        grupo = modules.ModelList('Matrículas', 
           [ 'core.models.Aluno',
             'core.models.Matricula',
             'core.models.ModuloAtivo',
           ])

        item = items.MenuItem(u"Orçamentos", "%s%s" % (reverse('admin:core_matricula_changelist'), "?status__exact=O" ) )

        grupo.children += [ item ] 

        self.children += [ grupo, 

          modules.ModelList('Controle de Presença', [ 
                                          'core.models.Aula',
                                          'core.models.Pauta',
                                          'core.models.Presenca',
                                          'core.models.PautaModulo',                              
                                          ])
        ]
Foi útil?

Solução

I ran into same problem and Tried to use items.MenuItem like you did, but I got an error:

'MenuItem' object has no attribute 'id'.

Then I came to follwing solution:
Even if we need only one link, we should create LinkList

link = modules.LinkList(
            title='', # the title is empty for better looking
            children=[
                [_(u'My link'), reverse('admin:custom_view')],
            ]
        )

Here is our ModelList:

models = modules.ModelList(
            models=(
                'app.models.Model1',
                'app.models.Model2',
                )
            )

And the Group, where we unite link with models:

a_group = modules.Group(
            title=u'My group',
            display="stacked",
            children=[
                models,
                link
            ]
        )

Then just use a_group anywhere you want.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top