我有一个 django 模型(A),它有一个 ManyToManyField(类型)到另一个模型(B)。从概念上讲,A 中的字段是“可选地将此对象限制为这些值”。我已经在 ManyToManyField 上设置了blank=null
和。null=True
我已经从这个模型创建了一个对象,并将类型设置为一些值。一切都很好。
我想将它设置为'null',即禁用它。但在 django shell 中,我收到以下错误:
>>> o.types.all()
[<Type: foo>, <Type: bar>]
>>> o.types = None
File "<console>", line 1, in <module>
File ".../virtualenv/lib/python2.6/site-packages/django/db/models/fields/related.py", line 627, in __set__
manager.add(*value)
TypeError: add() argument after * must be a sequence, not NoneType
我可以成功地将其设置为[]
(空列表),但我想将其设置为 None,因为我想使用 None 作为信号/标志。这在 Django 模型中可行吗?
我正在使用 Django 1.1