[Answered ]-Searching via multiple form fields?

2๐Ÿ‘

โœ…

I think you need Q objects. See: https://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects

From the docs:

Poll.objects.get(
    Q(question__startswith='Who'),
    Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6))
)

Translates to:

SELECT * from polls WHERE question LIKE 'Who%'
     AND (pub_date = '2005-05-02' OR pub_date = '2005-05-06')

You can populate the Q query from your cleaned form โ€“ you might even want to override clean() and return the queryset that way, so that you could just access the query set from the validated form.

๐Ÿ‘คbjw

Leave a comment