Search code examples
djangodjango-filterdjango-filters

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


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


Solution

  • 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