django-autocomplete-light
django-autocomplete-light copied to clipboard
Easy way to rank returned choices?
Is there a way to rank choices, eg if we search on "name" and "description" but name is more important?
Not afaik
You cat sort query by python list.sort() method. I am use it in this way:
def get_queryset(self):
if not self.request.user.is_authenticated:
return TeachingProgram.objects.none()
if self.q:
queryset = TeachingProgram.objects.filter(saved_str__icontains=self.q)
queryset = list(queryset)
queryset.sort(key=lambda teaching_program: (teaching_program.study_program.year,
teaching_program.study_program.specialty.name,
list(map(int, teaching_program.number.split('.')))))
else:
queryset = TeachingProgram.objects.all()
return queryset```