passing multiple values to a single column name when filtering records in django

33 views Asked by At

I'm trying to filter records in django. The issue is that I want to pass multiple values in the filter method.

Example : brand = laptops.object.filter(brand__icontains="apple") In this example, as far as I know, I can pass one value to the brand__icontains.

I want to filter the records with more than one value. Like filtering laptops based on brand like apple, dell, hp

1

There are 1 answers

0
SimbaOG On BEST ANSWER

You can use the '__in' parameter and pass the array of values like this:

brand = Laptops.objects.filter(brand__contains=['dell', 'apple']

__in QuerySet Reference