Here is a sample model I have:
class Commission(models.Model):
status = models.CharField(null=True, blank=True)
customer_name = models.CharField(null=True, blank=True)
order_dat = models.CharField(null=True, blank=True)
For status, I can have up to 10 different status types, such as: requested, confirmed, paid...
If I want to build a way to dynamically filter all orders with a specific status with a specific customer, I would do the following:
sample_kwargs['status'] = 'active'
sample_kwargs['custom_name'] = 'John Doe'
Then get my results with the following:
all_commmissions = Commission.objects.filter(**sample_kwargs)
This all works well, but what I am now trying to do is is get all the customer's orders that are equal to multiple statuses. For example, I want all of John Doe's orders that are equal to both confirmed, and paid.
Normally I'd used the Q filter
all_commmissions = Commission.objects.filter(
Q(status='confirmed') |
Q(status='paid'))
But this only allows me to hard code things in. How can I build a complex dynamic query (such as my sample_kwargs example) that uses OR? Or what is the best way I can achieve this? I could not find anything in the documentation. Thank you for your help.