1👍
✅
You need to or the Q objects with the |
operator:
params = Q(salt_spray__iregex=keyword) | Q(special_function__iregex=keyword) | Q(comment__iregex=keyword)
if data.get('market'):
params |= Q(project__market=data['market'])
Model.objects.filter(params)
Or use operator.or_
as @rinti has mentioned.
0👍
import operator
then you can do it like this:
params = []
# Add as much as you like to your list dynamically
params.append(Q(something))
Model.objects.filter(reduce(operator.or_, params))
- [Answer]-Deploy django webserver on apache
- [Answer]-How to pass two or more objects from views for render it in template
- [Answer]-Django: how to build relations and queries the best way?
- [Answer]-How to get the ip address who are accessing my website using django for python
- [Answer]-How to configure Celery loglevel in Supervisord
Source:stackexchange.com