python - 我如何在 django admin 的所有 View 中拥有 app_list

标签 python django

我正在覆盖该网站的 django 管理。 在默认索引页面中,它们具有 app_list 变量,其中包含所有应用程序及其模型。

但是 app_list 的其他 View 不可用,但我希望在所有 View 中都可用,以便我可以将它们放在侧边栏上供点击

在此文件中

https://github.com/django/django/blob/master/django/contrib/admin/sites.py#L382

他们有这样的代码

app_list = list(six.itervalues(app_dict))

但是我怎样才能在change_list页面中使用它

最佳答案

我知道已经晚了 7 年,但我想指出,因为我遇到过你的情况。如果您的目的是获取所有应用程序(应用程序列表)及其各自的型号,那么您可以使用 available_apps 而不是 app_list,如 available_apps > 可以在所有管理页面中访问(请参阅下面的 site.py 代码)

def each_context(self, request):
    """
    Return a dictionary of variables to put in the template context for
    *every* page in the admin site.
    For sites running on a subpath, use the SCRIPT_NAME value if site_url
    hasn't been customized.
    """
    script_name = request.META['SCRIPT_NAME']
    site_url = script_name if self.site_url == '/' and script_name else self.site_url
    return {
        'site_title': self.site_title,
        'site_header': self.site_header,
        'site_url': site_url,
        'has_permission': self.has_permission(request),
        'available_apps': self.get_app_list(request), #this one
        'is_popup': False,
    }

关于python - 我如何在 django admin 的所有 View 中拥有 app_list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15241594/

相关文章:

python - Matplotlib 绘图仅在循环中绘制最终绘图

python - 通过使用 numpy 平均相邻值来减小数组大小

python - Pandas:使用两个数据框进行垂直查找

python - 奇怪的是,使用某些 URL 无法为 Amazon Mechanical Turk 制作 HIT?

python pandas date time 输出日期相同

django - 如何使用表单对象更改提交的表单数据的值并重新显示它?

python - django 中的 Model.id 和 Model.pk 有什么区别?

没有 Action 的 HTML 表单

python - QuerySet 对象没有属性

python - 将 Windows Azure 辅助角色与 Celery 结合使用