python - How does Django implement the following dynamic query with empty parameters?
PHPz
PHPz 2017-05-27 17:39:19
0
2
942

Enter any one of the last six digits of your mobile phone number or ID card, and one of the results will be returned.
Enter the mobile phone number and the last six digits of the ID card at the same time, and the result will be returned.

I would like to ask how to deal with this logic?

PHPz
PHPz

学习是最好的投资!

reply all(2)
洪涛
mobile = request.GET.get('mobile', None)
id_no = request.GET.get('id_no', None)

data_list = XXX.objects.all()
if mobile:
    data_list = data_list.filter(mobile=mobile)
if id_no:
    data_list = data_list.filter(id_no=id_no)
迷茫
filter = {}
if mobile:
    filter['mobile'] = mobile
if card:
    filter['card'] = card
if status:
    filter['status'] = status

TableModel.objects.filter(**filter)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template