How to get the history of an object in django admin?

django, django-admin, django-models

Solution

That info is stored in the `LogEntry` model.

from django.contrib.admin.models import LogEntry

and its definition is:

class LogEntry(models.Model):
    action_time = models.DateTimeField(_('action time'), auto_now=True)
    user = models.ForeignKey(settings.AUTH_USER_MODEL)
    content_type = models.ForeignKey(ContentType, blank=True, null=True)
    object_id = models.TextField(_('object id'), blank=True, null=True)
    object_repr = models.CharField(_('object repr'), max_length=200)
    action_flag = models.PositiveSmallIntegerField(_('action flag'))
    change_message = models.TextField(_('change message'), blank=True)

    objects = LogEntryManager()

More info in the source code

Make sure that you access this in ReadOnly mode, else you would be messing up your log history.

Problem

I added a new field in one of my models and I would like to full it in with the name of a user who did a certain action (here, Validated by: USER). The easiest way I see is to get it from the history where this infos already is. From this picture, for example, I would get the User 'admin' if he performed the action 'Changed email' How to get the history of an object (as seen in the django Admin) ?

Original source