问题
Does anybody know how can I filter data even the passing value is False, it so hassle to make lot of conditions I think there is a way to filter data even the value is false or empty.
views.py
def sample(request):
if request.method=='POST':
province = request.POST.get('province', False)
municipality = request.POST.get('municipality', False)
barangay = request.POST.get('barangay', False)
status = request.POST.get('stats', False)
batch= request.POST.get('Pbatch', False)
it_batch= request.POST.get('Itbatch', False)
filter= Person.objects.filter(province=province, municipality=municipality,
barangay=barangay,status=status,batch=batch,it_batch=it_batch)
return render .. so on and so on...
The problem is when some data has no value or let say false it didn't recognize the data filter, is there any solution or idea how to achieve this?
来源:https://stackoverflow.com/questions/64893544/filter-data-disregard-null-value-when-filtering-in-django