Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I display last actions of everyone in the Django Admin index?

Is there a way to display every last actions made in the Django admin? By default the admin display only last actions of the current user but I would like to see last actions of every administrators. Since I don't have any code of this page in my project, how can I interact with this widget? Should I override the whole index?

I would like to get something like this:

Result expected in the admin interface

instead of just the 2 first entries if I'm connected as er**** (according to the screen).

like image 712
Maxime Lorant Avatar asked Mar 12 '14 21:03

Maxime Lorant


1 Answers

Yes, it is. Everything in the Django admin is customizable by overriding the template. All you need is to override the file templates/admin/index.html of your current Django version and change this line:

{% get_admin_log 10 as admin_log for_user user %}

and remove the for_user user part. It will display the 10 last recent actions, without filtering by user. To be perfect, you also need to change the name of the block and add action author. The sidebar block should be something like:

{% 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 %}
like image 72
Maxime Lorant Avatar answered Oct 17 '22 06:10

Maxime Lorant