try 这样做:
wishList = WishList.objects.get(pk=20)
matches = [val for val in Store.attribute_answers.all() if val in wishList.attribute_answers]
还有这个...
'ManyRelatedManager' object is not iterable
这两个字段都是多对多的,如何才能做到这一点呢?
try 这样做:
wishList = WishList.objects.get(pk=20)
matches = [val for val in Store.attribute_answers.all() if val in wishList.attribute_answers]
还有这个...
'ManyRelatedManager' object is not iterable
这两个字段都是多对多的,如何才能做到这一点呢?
try
matches = [val for val in Store.attribute_answers.all() if val in WishList.attribute_answers.all()]
注意WishList.attribute_answers.all()
结尾的括号.添加括号将调用all
函数返回一个iterable.
如果你加上括号,你的意思是"给我store 答案中的所有值,只要该值也在愿望 list 答案中".如果没有括号,你需要的是store 答案中的所有值,这些值也在all
函数中,这是没有意义的.all函数不是iterable(它是一个返回iterable的函数)