Re: How to order queries by exact match first

2013-03-06 Thread Gabriel
I'm not sure this is the right way, but you could drop the Q objects, use only icontains and sort by the length of 'name' -- 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

Re: How to order queries by exact match first

2013-03-06 Thread Tom Evans
On Wed, Mar 6, 2013 at 11:58 AM, Alexander Todorov wrote: > Hi guys, > I have this type of query: > > .filter(name__icontains='celery') > > and will possibly replace it with > > .filter(Q(name='celery') | Q(name__icontains='celery')) > > > I want to get the results

How to order queries by exact match first

2013-03-06 Thread Alexander Todorov
Hi guys, I have this type of query: .filter(name__icontains='celery') and will possibly replace it with .filter(Q(name='celery') | Q(name__icontains='celery')) I want to get the results ordered by exact match first. Is this possible or I need to sort the results in my code? Regards, Alex