简体   繁体   English

如何清空 django 中的多对多字段

[英]How to empty a many to many field in django

I would like to empty all things within the following many to many field( weekday_with_class ):我想清空以下多对多字段( weekday_with_class )中的所有内容:

 all_existing_class.weekday_with_class = None

Here is the models.py:这是models.py:

   weekday_with_class = models.ManyToManyField('Weekday', blank=True, related_name='weekday_with_class')

However, if I execute the above code, I get this error:但是,如果我执行上面的代码,我会得到这个错误:

Direct assignment to the forward side of a many-to-many set is prohibited. Use weekday_with_class.set() instead.

How is it possible to basically make my weekday_with_class empty for an instance?怎么可能基本上让我的weekday_with_class为空? Thank you, and please leave a comment if you need any more information.谢谢,如果您需要更多信息,请发表评论。

all_existing_class.weekday_with_class.clear()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM