Django Генерирование списка противоположных моделей

I am trying to develop a program that will determine what plants are beneficial and harmful to other plants. I want it to be able to run through a list of plants and compare and see if one plant's deters_insects_and_animals species matches the other plant's pests then it adds it to the list in ally_deter_pests_for(self): I'm not really sure how to do that.

For example, it would find that marigolds deter flea beetles, and broccoli is affected by flea beetles. Therefore, marigolds ally_deter_pest_for(self):would x.append(broccoli)

Прямо сейчас я получаю ошибку

cannot unpack non-iterable ManyRelatedManager object

Сначала вам нужно получить все связанные объекты.

for i in range(len(self.deters_insect_and_animals.all())):
    # further code

Отношения: Отношения "многие ко многим"

Вернуться на верх