title: How to add a sortable column from the admin log in Django
body: <p>In the Django admin area I need to display when an object was last modified by another user. Therefore I want to leverage Django’s built-in admin log. I came up with this solution:</p>
  
  <pre><code>class MyModel(models.Model):
      ...
  
      @property
      def admin_last_modified(self):
          from django.contrib.admin.models import LogEntry
          from django.contrib.contenttypes.models import ContentType
          try:
              logentry = LogEntry.objects.filter(
                  object_id=self.pk,
                  content_type_id=ContentType.objects.get_for_model(self.__class__)
              ).order_by('action_time')[0]
          except:
              return ''
          return '{} by {}'.format(logentry.action_time, logentry.user)
  </code></pre>
  
  <p>and the admin class:</p>
  
  <pre><code>@admin.register(MyModel)
  class MyAdmin(admin.ModelAdmin):
      list_display = ( ..., 'admin_last_modified' )
  </code></pre>
  
  <p>The disadvantage, which is a show-stopper for me, is that the column is not sortable.</p>
  
  <p>For that, from what I’ve gathered, I'd need to re-formulate the property as some kind of annotation. But I’ve tried and haven’t come up with an idea how to do so:</p>
  
  <pre><code>class MyAdmin(admin.ModelAdmin):
  
     def get_queryset(self):
         queryset = super().get_queryset(request)
         queryset = queryset.annotate(
             admin_last_modified=# ???
         )
         return queryset
  </code></pre>
  
  <p>I’m now looking for what to substitute the question marks with.</p>
  
  <p>How can I write an annotation, that fetches one row of information from another basically unrelated table?</p>