gpt4 book ai didi

django - 属性错误 : 'RelatedManager' object has no attribute 'remove'

转载 作者:行者123 更新时间:2023-12-04 14:55:02 25 4
gpt4 key购买 nike

在我的代码中的某处说

publisher.publisherperson_set.remove(email__in=pp_remove_set)

执行此操作后,我得到了

AttributeError: 'RelatedManager' object has no attribute 'remove'



事实上:我看着 dir(publisher.publisherperson_set)它有很多操作(包括 add ),但没有 remove .

在什么情况下这是可能的?

最佳答案

不能是 null
documentation for RelatedManager.remove()

For ForeignKey objects, this method only exists if null=True. If the related field can’t be set to None (NULL), then an object can’t be removed from a relation without being added to another.



很明显,一旦你想到它。
我真正想做的是:
publisher.publisherperson_set.filter(email__in=pp_remove_set).delete()

关于django - 属性错误 : 'RelatedManager' object has no attribute 'remove' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46178144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com