Answer the question
In order to leave comments, you need to log in
How to make a filter in django using dictionary and iexact?
Hello, how is it possible to make a filter using a case-insensitive entry and some dictionary from request.GET?
That is, I have a certain form that is built according to the forms.ModelForm model. As a result of receiving, I form a dictionary. and I use it. I give the code below:
filter_map = {}
def set_if_not_none(mapping, key, value):
if value is not None and value is not '' and key != 'order_by':
mapping[key] = value
for req_key, req_value in dict(request.GET).items():
set_if_not_none(filter_map,req_key,req_value[0])
debtors_list = Debtors.objects.filter(**filter_map).order_by(ordering)
Answer the question
In order to leave comments, you need to log in
filter_map = {}
def set_if_not_none(mapping, key, value):
if value is not None and value is not '' and key != 'order_by':
mapping['{}__iexact'.format(key)] = value
for req_key, req_value in dict(request.GET).items():
set_if_not_none(filter_map,req_key,req_value[0])
debtors_list = Debtors.objects.filter(**filter_map).order_by(ordering)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question