Skip to content

Instantly share code, notes, and snippets.

@iorlas
Forked from anonymous/gist:89741e8ef2bf412f3a63
Last active February 16, 2016 16:02
Show Gist options
  • Save iorlas/6add7151f2232949bfc4 to your computer and use it in GitHub Desktop.
Save iorlas/6add7151f2232949bfc4 to your computer and use it in GitHub Desktop.
#Функия для сортировки тредам по последним ответам или дате создания
threads = Thread.objects.all().prefetch_related('posts')
def thread_list_f(threads):
work_list = []
thread_list = []
for element in threads:
try:
work_list.append(element.posts.all()[::-1][0].post_time)
except IndexError:
work_list.append(element.thread_time)
work_list.sort()
work_list.reverse()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment