如何删除外键?
我有两个模型:
class Child(models.Model):
name = models.CharField(max_length=256, null=True, blank=True)
parent = models.ForeignKey(to=Parent, null=True, related_name="children", on_delete=models.DO_NOTHING)
class Parent(models.Model):
name = models.CharField(max_length=256, null=True, blank=True)
def unbind_children(self): # there I want to unbind all children
# how to realize this?
我想解除孩子的绑定,我的意思是我想让特殊的 Parent 相关Child实例的 parent 字段为None.
手掌心
相关分类