I'm trying to make a "page last updated by (username)" on (date)" line at the bottom of my mezzanine site page. I've successfully got the date part with the syntax:
{{ page.updated|date:"M d, Y" }}
but the username seems more complicated. I have a nice list in django_admin_log containing action_time, user_id and object_id and I can access & display object_id from within my template using {{ page.id }}.
The username is in auth_user and in days of old I would have put in some SQL with a nice table join on user_id to retrieve this information and display it.
I can't seem to get the syntax right - this kind of thing looked promising:
page.objects.raw("select id, title from page")
but no matter how I try to massage it into my base.html with {{ xxx }} or {% xxx %}, I always seem to get an error.
Thanks for any pointers
You should use the
LogEntrymodel[1].I would probably make a custom context processor[2] that get's the request's Page, finds the newest LogEntry for the Page instance and adds
updated_onandupdated_bycontext variables.[1] https://github.com/django/django/blob/master/django/contrib/admin/models.py#L27
[2] https://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-own-context-processors