Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Created June 5, 2013 11:04
Show Gist options
  • Save kezabelle/5713130 to your computer and use it in GitHub Desktop.
Save kezabelle/5713130 to your computer and use it in GitHub Desktop.
Get the author of any object, in a generic way, assuming the content was administered through the Django admin.
def author(self):
entries = (LogEntry.objects
.filter(content_type=ContentType.objects.get_for_model(self), object_id=self.pk)
.filter(Q(action_flag=ADDITION | Q(action_flag=CHANGE)))
# switch to -action_time if you want the last edit, rather than the first.
return entries.order_by('action_time')[:1][0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment