Hello there,
I have the following situation:
I have a (yet unresolved) queryset of Product which I suppose I need to filter by chaining an unknown number of Q expressions in an OR relationship.
Basically, I would need to do this:
incoming_filters = {
product_type_id1: [product_property_id1, ...],
product_type_id2: [product_property_id2, ...],
product_type_id3: [product_property_id3, ...],
...
}
product_queryset.filter(
Q(product_type=product_type_id1, product_properties__in=[product_property_id1, ...])
|
Q(product_type=product_type_id2, product_properties__in=[product_property_id2, ...])
|
Q(product_type=product_type_id3, product_properties__in=[product_property_id3, ...])
|
...
)
How could I do this?
Some extra info:
To make matters worse, there is actually an intermediary between Product on the one side, and ProductType and ProductProperty on the other side:
Product <=OneToOne== ProductTagging ==ForeignKey=> ProductType
Product <=OneToOne== ProductTagging <=ManyToMany== ProductProperty
I don’t initiate the queryset, I’m getting it from “the messy part” of the code, which I’d rather not modify. It’s the reason why I can’t start from “ProductTagging” and save myself some trouble.