Last active
June 7, 2018 19:00
-
-
Save hancush/c5126f8a74f594bb6f19be2e5c4cfed5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import Q | |
condition = Q() | |
employers = Employer.objects.all() | |
if params: | |
if params.get('name'): | |
employers = employers.annotate(search_vector=SearchVector('name')) | |
name = Q(search_vector=params.get('name')) | |
condition &= name | |
if params.get('employer'): | |
name = Q(slug=params.get('employer')) | |
condition &= name | |
if params.get('parent'): | |
parent = Q(parent__slug=params.get('parent')) | |
condition &= parent | |
return employers.filter(condition) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment