Clive Bruton
unread,Jul 6, 2020, 12:03:34 PM7/6/20Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
I am working into someone else's solution, with this code in forms.py:
***************
class SearchForm(forms.Form):
area = forms.ModelChoiceField(label=_('Area'),
queryset=Area.objects.all(), required=False)
group = forms.ModelChoiceField(label=_('Group'),
queryset=Group.objects.all(), required=False)
q = forms.CharField(required=False, label=_('Query'),)
def filter_by(self):
# TODO search using more than one field
# TODO split query string and make seaprate search by words
filters = {}
if self.cleaned_data['group']:
filters['group'] = self.cleaned_data['group']
if self.cleaned_data['area']:
filters['area'] = self.cleaned_data['area']
filters['description__icontains'] = self.cleaned_data['q']
return filters
***************
I understand that 'filters' is a dictionary.
However, what I would like to do is have the final input ('q') be an
'or' search on two fields, ie:
filter(Q(description__icontains = self.cleaned_data['q']) | Q
(title__icontains = self.cleaned_data['q'])]
Not sure how to implement that in this dictionary style.
Thanks
-- Clive