def get_latest_file_attachments(file_attachments):
 file_attachment_histories = FileAttachmentHistory.objects.filter(file_attachments__in=file_attachments)
 latest = {data[u'id']: data[u'latest_revision'] for data in file_attachment_histories.values(u'id', u'latest_revision')}
 return [f for f in file_attachments if ((not f.is_from_diff) and (f.attachment_revision == latest[f.attachment_history_id]))]

def get_latest_file_attachments ( file_attachments ) : file_attachment_histories = FileAttachmentHistory . objects . filter ( file_attachments__in = file_attachments ) latest = { data [ u'id' ] : data [ u'latest_revision' ] for data in file_attachment_histories . values ( u'id' , u'latest_revision' ) } return [ f for f in file_attachments if ( ( not f . is_from_diff ) and ( f . attachment_revision == latest [ f . attachment_history_id ] ) ) ]
filter the list of file attachments to only return the latest revisions .