django - 这是PyCharm 4.0.5中的错误吗?

标签 django python-3.x pycharm

我昨天更新到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/

相关文章:

pycharm - 我可以更改PyCharmProjects的位置/名称吗?

python - 在 Django 代理中间件中允许逐跳 header

django - 从 django View 获取媒体文件夹的绝对路径

python-3.x - 列表列表-删除字符

python - 为什么 python 整数缓存范围 [-5, 256] 不能在所有平台上以类似的方式工作?

python - 运行以退出代码 -1 结束的 Pycharm 调试

python - 当我将模型实例保存到 MongoDB 数据库中时,为什么 Python 会引发异常?

Python 使用 Django 将 python-amazon-simple-product-api 结果转换为 json

python-3.x - 为什么下载 x86-64 python 安装程序会导致我的 PC 上出现 32 位设置?

python - time.clock(),在函数定义内部使用时出现奇怪的结果