Reputation: 3875
In django admin, we can define custom templates per app. In this case, I'm customising the app_index.html
template for my application.
I'd like to add a few graphs and other to that page. Now that I've overridden the template, how can I override the corresponding view method?
I thought about making a custom AdminSite
and override the app_index()
(see https://github.com/django/django/blob/master/django/contrib/admin/sites.py#L511) method, but I have more than one application in my django installation, all of which will have a custom app_index.html
.
What's the best way to add context to the app_index.html
template?
Upvotes: 0
Views: 1298
Reputation: 1004
Don't know if this is the best way, but it can be done with template tags. Here is how I did it:
# <app>/templatetags/erp.py
register = template.Library()
@register.assignment_tag
def erp_get_tasks ():
return Task.objects.exclude (done=True).order_by ('priority')
.
# <app>/templates/admin/erp/app_index.html
{% extends "admin/app_index.html" %}
{% load erp %}
...
{% block footer %}
{% erp_get_tasks as tasks %}
{% for task in tasks %}
...
Upvotes: 1