You can construct a Q
object that is a disjunction of the options:
from django.http import JsonResponse
if showall != 'true':
filters = []
if showfl_1 == 'true':
filters.append(('listing', 'filtered1'))
if showfl_1 == 'true':
filters.append(('listing', 'filtered2'))
if not filters:
searchresult = User_data.objects.none()
else:
searchresult = Q(*filters, _connector=Q.OR)
else:
searchresult = User_data.objects.all()
searchresult = list(searchresult.values_list(
'Country','gender','listing'
).order_by('-added_date'))
return JsonResponse({'data': searchresult})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…