How to add data to a django admin change_list page taken from a different model?
I would like to add a bit of information to a certain change_list admin page. The info is taken from a queryset on a different model than that presented in开发者_StackOverflow中文版 this template. How do I go about doing this?
Try to rewrite changelist_view
function in your admin class:
class MyModelAdmin(admin.ModelAdmin):
# .....
def changelist_view(self, request, extra_context=None):
extra = {'foo': bar}
extra.update(extra_context or {})
return super(MyModelAdmin, self).changelist_view(request, extra_context=extra)
# .....
You can create a custom context processor. This allows you to expose a variable to the whole application. It works on pages rendered using RequestContext, tried this with the admin pages and it works.
Use a Custom Template Tag - you can fetch and use anything in it.
精彩评论