Last active
September 22, 2018 00:11
-
-
Save olivx/89f2f52a471c602a24d680937a655bea to your computer and use it in GitHub Desktop.
filter_applicants multiples elements separator per ', ' example with Q() object
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
def add_q_object(self, keyword, q_object, query_parm): | |
for key in keyword: | |
kwargs = {query_parm: key.strip()} | |
q_object.add(Q(**kwargs), q_object.OR) | |
def filter_applicants(self, _queryset=None): | |
my_applicants = _queryset | |
self.is_valid() | |
q_object_cpf = Q() | |
if self.cleaned_data['cpf_bar']: | |
cpf_bar = self.cleaned_data['cpf_bar'] | |
self.add_q_object(cpf_bar.split(','), q_object_cpf, | |
'candidate__usercpf__cpf') | |
return my_applicants.filter((q_object_cpf)).distinct() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment