Reputation: 3890
I'm trying to override Django admin index.html to show table contain latest 5 records from a model
I managed to override the template with the following in my app:
from django.contrib import admin
admin.site.index_template = 'admin/dashboard.html'
admin.autodiscover()
But i have no idea how to add the latest records from model as a context to the index.html
Hope someone can help me
Upvotes: 2
Views: 1551
Reputation: 21
Something that worked for me to add extra context was using context processor. Explained here: https://stackoverflow.com/a/34903331/13436391
Upvotes: 1
Reputation: 455
class CustomAdminSite(admin.AdminSite):
def index(self, request, extra_context=None):
extra_context = extra_context or {}
# Add your context here
return super(CustomAdminSite, self).index(request, extra_context)
admin_site = CustomAdminSite()
Don't forget to replace default admin
with admin_site
Upvotes: 1