Skip to content

Instantly share code, notes, and snippets.

@rg3915
Forked from olivx/filter_applicants.py
Created September 22, 2018 00:11
Show Gist options
  • Save rg3915/143dbeef36c538039e65f06640273494 to your computer and use it in GitHub Desktop.
Save rg3915/143dbeef36c538039e65f06640273494 to your computer and use it in GitHub Desktop.
filter_applicants multiples elements separator per ', ' example with Q() object
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