[Answered ]-How can I order query results by which field matched in Django?

2👍

Django prepares and then does one query to db, but you can call force by convert queryset to list, for example:

good_matches = models.Post.objects.filter(
        Q(title__icontains=term))
just_ok_matches = models.Post.objects.filter(
        ~Q(title__icontains=term) & Q(description__icontains=term)
    )
posts = list(good_matches) + list(just_ok_matches)

Leave a comment