B
B
blackbb2017-08-13 12:56:51
Django
blackbb, 2017-08-13 12:56:51

What is the right way to write a for loop in my case?

class Order(models.Model):
    work = models.ManyToManyField(Work, verbose_name='Виды работ')
class Master(models.Model):
    work = models.ManyToManyField(Work, verbose_name='Виды работ')

order = Order.objects.get(id='1')
master_list = []
    for item in Master.objects.all():
        if item.work == order.work:
            master_list.append(item)

The master_list is always empty. The work field of order and item is bound to the same model via ManyToMany. Why is item.work not identical to order.work in this case? Although there are masters who have the same work as in the order.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tema_sun, 2017-08-13
@blackbb

https://stackoverflow.com/questions/16324362/djang...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question