2👍
✅
Since you need to filter the queryset object, you can do something like this in your view:
from django.db.models import Q
matches = ['cat', 'kitty', 'meow']
messages = Message.objects.filter(reduce(operator.or_, (Q(message__contains=match) for match in matches))) #Or use icontains if you want a case insensitive match.
1👍
The filter should be a method of a MessageManager. See here: https://docs.djangoproject.com/en/dev/topics/db/managers/
- [Django]-Handle variable that could be None
- [Django]-Django: how to consume incoming POST data as a file-like obj for streaming processing
- [Django]-How to mock django settings attributes in pytest-django
- [Django]-Django test model with fake user
Source:stackexchange.com