I have Django list view but I want to put search based on two columns. how to implement this. User would be able to search records based on two columns in same view.
I think you can do it by |
and using Q
like below:
from django.db.models import Q
YourModel.objects.filter(Q(column_1__icontains=searched_keyword) | Q(
column_2__icontains=searched_keyword))
I think this can help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.