[Answered ]-Django Queryset most accurate search result

2๐Ÿ‘

โœ…

So, you want to make objects with certain tags to display in the top?

There is similar problem. The idea is to add in select new field, which will hold boolean value, so you can sort by it.

You should add this field using django extra queryset method.

MyModel.objects.extra(
    select={
        'tags_occurance': "(tags LIKE '%tag1%') + (tags LIKE '%tag2%')"
    },
).order_by('-tags_occurance')

Should be something like this.

๐Ÿ‘คdt0xff

Leave a comment