[Answered ]-Performing a Django Query on a Model, But Ending Up with a QuerySet for That Model's ManyToManyField

1👍

If you want to get a Product queryset you have to filter the Product objects and filter via the reverse relation for product color:

products = Product.objects.filter(productcolor_set__r__gte=x).distinct()

1👍

You can use the range field lookup:

You can use range anywhere you can use
BETWEEN in SQL — for dates, numbers
and even characters.

your query:

r_range, g_range, b_range = ((3,130),(0,255),(0,255))

products = Product.objects.filter(productcolor_set__r__range=r_range, 
    productcolor_set__g__range=g_range,
    productcolor_set__b__range=b_range).distinct()
👤dting

Leave a comment