From c12f4b2715b56f8ccbdf2ace70ba584b72dc1dce Mon Sep 17 00:00:00 2001 From: hardythe1 Date: Tue, 30 Sep 2014 17:28:00 +0530 Subject: trying to implement natural sorting --- tbc/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tbc/views.py b/tbc/views.py index 5167978..21f059c 100755 --- a/tbc/views.py +++ b/tbc/views.py @@ -451,7 +451,8 @@ def BookDetails(request, book_id=None): else: context['user'] = request.user book = Book.objects.get(id=book_id) - chapters = Chapters.objects.filter(book=book).order_by('name','pk') + query = 'SELECT * from tbc_chapters where book_id = (SELECT id from tbc_book where id='+book_id+') ORDER BY LENGTH(name), name;' + chapters = Chapters.objects.raw(query) images = ScreenShots.objects.filter(book=book) context['chapters'] = chapters context['images'] = images @@ -464,7 +465,8 @@ def BookReview(request, book_id=None): if is_reviewer(request.user): if book_id: book = Book.objects.get(id=book_id) - chapters = Chapters.objects.filter(book=book).order_by('id') + query = 'SELECT * from tbc_chapters where book_id = (SELECT id from tbc_book where id='+book_id+') ORDER BY LENGTH(name), name;' + chapters = Chapters.objects.raw(query) images = ScreenShots.objects.filter(book=book) context['chapters'] = chapters context['images'] = images -- cgit