有没有办法显示在 Django 管理员中所做的每一个最后的 Action ?默认情况下,管理员仅显示当前用户的最后操作,但我想查看每个管理员的最后操作。自 我的项目中没有此页面的任何代码 ,我如何与这个小部件交互?我应该覆盖整个索引吗?
我想得到这样的东西:
如果我以 er****
的身份连接,而不仅仅是前 2 个条目(根据屏幕)。
最佳答案
是的。 Django 管理中的所有内容都是 通过覆盖模板进行定制 .您只需要覆盖文件 templates/admin/index.html
of your current Django version并更改此行:
{% get_admin_log 10 as admin_log for_user user %}
并删除
for_user user
部分。它将显示最近的 10 个操作,无需用户过滤。为了完美,您还需要更改块的名称并添加 Action 作者。侧边栏块应该是这样的:{% block sidebar %}
<div id="content-related">
<div class="module" id="recent-actions-module">
<h2>{% trans 'Recent Actions' %}</h2>
<h3>{% trans 'Last Actions' %}</h3> {# Title modified #}
{% load log %}
{% get_admin_log 10 as admin_log %} {# No more filtering #}
{% if not admin_log %}
<p>{% trans 'None available' %}</p>
{% else %}
<ul class="actionlist">
{% for entry in admin_log %}
<li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}">
{% if entry.is_deletion or not entry.get_admin_url %}
{{ entry.object_repr }}
{% else %}
<a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
{% endif %}
<br/>
{% if entry.content_type %}
{# Add the author here, at the end #}
<span class="mini quiet">{% filter capfirst %}{% trans entry.content_type.name %}{% endfilter %}, by {{ entry.user }}</span>
{% else %}
<span class="mini quiet">{% trans 'Unknown content' %}</span>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
{% endblock %}
关于django - 我可以在 Django Admin 索引中显示每个人的最后操作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22364067/