Reputation: 153
I have six text box in search field and user can enter either of the values. I capture those values in view by:
if request.GET:
result_list = []
client_build = request.GET.get('client_build','')
app_build = request.GET.get('app_build','')
ws_build = request.GET.get('ws_build','')
asset = request.GET.get('asset','')
feature = request.GET.get('feature','')
test_type = request.GET.get('test_type','')
result_lists = result.objects.filter(asset=asset,feature=feature, test_type=test_type)
job_list = job.objects.filter(client_build=client_build ,app_build = app_build,ws_build = ws_build)
When I try to filter them it gives "invalid literal for int() with base 10: ''" error! How can I get only those values which are entered by user and query in filter accordingly.
I referred to this post Django - multiple field search issues but i have six text box doing multiple if and else is not what I am looking for.
Upvotes: 0
Views: 98
Reputation: 22808
@vikalp.sahni is correct. You enter an integer but you didn't know that the input convert your answer into string. To fix that, as you said that the client_build is the only integer, it must be:
client_build = int(request.GET.get('client_build',''))
Overall I think your query is correct. Just remember to put int if it is integer.
Upvotes: 1