我昨天更新到PyCharm 4.0.5,从那时起,它一直在将一些完全有效的代码标记为错误。基本上,代码只是在ManyToMany关系上进行迭代。代码如下所示。
songs = []
for album in order.album_products.all():
album_songs = Song.objects.filter(album__exact=album.album_product.id)
if not album_songs:
for song in album_songs:
songs.append(song)
显示错误的行是这一行:
for album in order.album_products.all():
并且显示的错误是此错误:
Call 'all' directly on 'many-to-many with intermediate'. method 'all' can't be used with many-to-many relations if intermediate model is used.
我对此很困惑。只要我记得,这段代码就可以在Django中正常工作。从1.0或1.1版开始,我就一直在使用Django,并且始终使用此方法遍历ManyToMany关系。同时查看Stackoverflow答案也显示了许多其他人使用的相同代码。
有人有什么建议吗?
最佳答案
对我来说似乎是一个错误。我不知道在哪
method 'all' can't be used with many-to-many relations if intermediate model is used.
来自,但在Django文档中找不到。实际上,Django docs在"Extra fields on many-to-many relationships"部分的示例中使用了它:
>>> beatles.members.all()
这个错误是PyCharm中的already reported。
关于django - 这是PyCharm 4.0.5中的错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28988564/