Sunday, September 27, 2015

django query, order results such that th128 > th99

Is it possible to order the query result strings in such a way that th128 string would be first comparing to th99.
The query results contains 128 items in format: "th"+number. For instance, th1, th2, ...th80, ..th99, th100, th128.
Than i order results, they go in the following order, th1, th10,th100, th101,th102,... th11,th110, ... th2, th20, th21,th22,.. th9,..th99.
Thus i am not able to get the largest result, which is th128. I am getting th99 instead.

def temp(request):
    query = request.GET.get( 'q','')
    #a=Aref5.objects.filter(Rname__contains='book').count()  #finds128
    a=Aref5.objects.filter(Rname__contains='book').order_by('-Rname')[0:1].get() #gets aref5 object
    print(a.Rname) #prints th99 instead of th128, which logically is larger
    return render_to_response('Ath.html', {"query": query})

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/69e26bab-210e-4137-adf3-498855d0eae6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment