SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 3ae5518b authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Improve ProfileSearchForm query handling

parent ee6ccc82
No related branches found
No related tags found
No related merge requests found
......@@ -244,10 +244,14 @@ class ProfileDynSelForm(forms.Form):
def search_results(self):
if self.cleaned_data["q"]:
profiles = Profile.objects.filter(
Q(last_name__icontains=self.cleaned_data["q"])
| Q(first_name__icontains=self.cleaned_data["q"])
).distinct()
splitwords = self.cleaned_data["q"].split(" ")
query = Q()
for word in splitwords:
query = query & (
Q(last_name__icontains=word) |
Q(first_name__icontains=word)
)
profiles = Profile.objects.filter(query).distinct()
return profiles
else:
return Profile.objects.none()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment