10

i want to display additional sidebar in my django admin index. I have created templates/admin/index.html and it show up. Now i need some data from model. To do this I have created index function in the file admin/views.py

def index(request):
    var = 'var'
    return render_to_response('admin/index.html', {'var': var})

Without this function I have error ViewDoesNotExist.

However template not react for this sample variable 'var'. Moreover my app doesn't display in the index. I have only auth app.

I think that I'm overwriting index function form admin view. How to properly overwrite this function?

kierzniak
  • 606
  • 5
  • 15

2 Answers2

10

Instead of overwriting the view entirely, you can add logic to the views in your ModelAdmin (admin.py) class:

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#other-methods

so for example:

class MyAdmin(admin.ModelAdmin)
    ...
    def add_view(self, request, form_url='', extra_context=None):
        # Do some extra queries that will get passed to the template
        c = {'x':SomeModel.objects.all()}
        super(MyAdmin, self).add_view(request, extra_context=c)
Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
  • 1
    Good idea but:add_view - "Django view for the model instance addition page." I want to access data on index page there is no index_view method – kierzniak Oct 21 '11 at 11:51
2

Consider using django admin tools https://bitbucket.org/izi/django-admin-tools/wiki/Home

then you get commands like manage.py customdashboard, manage.py custommenu etc.

It even has a nice bookmark-functionality to quickliy jump to certain objects or list pages.

mawimawi
  • 4,222
  • 3
  • 33
  • 52