B
B
blackbb2017-08-12 22:26:18
Django
blackbb, 2017-08-12 22:26:18

How to filter an object by ManyToManyField?

order = Order.objects.get(id = order_id)
master_list = Master.objects.filter(work = order.work.all())

Order and Master have a "work" field, it's ManyToManyField. Let's say in "order" now the work field contains (plaster, whitewash). How to filter the masters so that only the masters that contain both plaster and whitewash in the "work" field are shown. Now masters are shown who contain either plaster or whitewash.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question