我想添加一个指向管理员索引页面的链接,其中列出了模型,但我不想创建新模型。这将是一个自定义 View 。
这就是我想要的结果。在这种情况下,排行榜应指向/admin/leaderboards。 代码和用户是有效的模型。
我尝试覆盖index.html页面,根据to the documentation ,使用以下模板。
{% extends "admin/index.html" %}
{% block content %}
{{ block.super }}
<div class="app-{{ app.app_label }} module">
<table>
<tr>
<th scope="row"><a href="leaderboards">Leaderboards</a></th>
<td></td>
</tr>
</table>
</div>
{% endblock %}
但这就是结果:
我知道我可以替换完整的index.html并在那里硬编码特定行,但很多人不建议这样做。还有其他选择吗?
最佳答案
Django actually recommends将 index.html 复制粘贴到应用程序文件夹,并硬编码链接。
On a similar note, you might want to customize the look and feel of the Django admin index page.
By default, it displays all the apps in INSTALLED_APPS that have been registered with the admin application, in alphabetical order. You may want to make significant changes to the layout. After all, the index is probably the most important page of the admin, and it should be easy to use.
The template to customize is admin/index.html. (Do the same as with admin/base_site.html in the previous section – copy it from the default directory to your custom template directory). Edit the file, and you’ll see it uses a template variable called app_list. That variable contains every installed Django app. Instead of using that, you can hard-code links to object-specific admin pages in whatever way you think is best.
关于python - 将 "fake"模型条目添加到管理索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40900700/