Version 2 (modified by anonymous, 18 years ago) ( diff )

--

Last update context processor

Here is a simple context processor that you can use to display the latest update to your site (using the history produced by the admin app).

def last_update(request):
    """Returns the last logged update with the admin."""
    from django.contrib.admin.models import LogEntry
    try:
        entry = LogEntry.objects.all().order_by('-action_time')[0]
    except IndexError:
        entry = None
    return {'last_update': entry}

Once you have added this to TEMPLATE_CONTEXT_PROCESSORS in your settings.py, you can use the following in your templates:

Site last updated: <a href="{{ last_update.get_edited_object.get_absolute_url }}">{{ last_update.action_time|date:"j M Y" }}</a>
Note: See TracWiki for help on using the wiki.
Back to Top