Django merged queryset, listing iterables with length of specified column
I want to write a basic search option for my site. I have two tables in my database, and I want to get two result from this database which meet my query.
from itertools import chain
res1 = table1.objects.filter(Q(label__istartswith = query)).extra(se开发者_如何学Clect={'length':'Length(label)'}).order_by('length')
res2 = table2.objects.filter(Q(label__istartswith = query)).extra(select={'length':'Length(label)'}).order_by('length')
res = list(chain(res1, res2)
Before the chain of iterations I got a true result which was listed to label length, but now I get table1
result listing with label of table1
length. After the first list then table2
result listing with label of table2
length...
I have tried making an array to append res1
and res2
to get what I need instead of the chaining operation, but I didnt succeed...
精彩评论