13👍
✅
Once you have all the field names you can create Q
objects using kwarg expansion and use reduce()
along with operator.or_
to turn them into a single query.
qgroup = reduce(operator.or_, (Q(**{fieldname: value}) for fieldname in fieldnames))
asgns = Assignment.objects.filter(qgroup)
0👍
Old question, but for further reference I am adding this:
In django 1.10 SearchVector class was added.
Usage from the docs:
Searching against a single field is great but rather limiting. The Entry instances we’re searching belong to a Blog, which has a tagline field. To query against both fields, use a SearchVector:
>>> from django.contrib.postgres.search import SearchVector
>>> Entry.objects.annotate(
... search=SearchVector('body_text', 'blog__tagline'),
... ).filter(search='Cheese')
[<Entry: Cheese on Toast recipes>, <Entry: Pizza Recipes>]
- [Django]-Django single sign on and Php site: cross domain login?
- [Django]-Implementing accent insensitive search on django using sqlite
- [Django]-How can i create Generated/Computed column Postgres/DJANGO?
- [Django]-How can you use Django template tags in a Jinja2 template?
Source:stackexchange.com