Hi Lewis,
looks like you already got the answer - using Q() objects helps a lot. I'll just add two things that might help:
- it's possible to prepare filters in advance which helps readability and code structure. I often do something similar to this:
from django.db.models import Q
filters = []
# search for tags
filters.append(tag='sometag')
# handle item title
filters.append(title__icontains='someword')
# only list active users
filters.append(is_active=True)
found = Resources.objects.filter(*filters)
- you might also want to check out for existing solutions if your case allows. I've recently switched most of my search functionality to django-watson and would not go back. There are other solutions avaliable of course, varying in complexity and capabilities.
Cheers
Jirka