0

在 Django 文档中,它提到当您直接指定新的相关集合时,不再在集合中的任何模型都只是解除关联而不是删除。

换句话说,如果你有这样的情况:

#author.books contains [book1, book2, book3]
author.books = [book1, book2]
author.save()

book 3 模型不再与作者关联,但并未删除。有没有办法解除和删除模型?

4

1 回答 1

0

If book3 is an model object, you would just run

book3.delete()

And it will disassociate it from the Author's books (if that is a Key or many-to-many key for example) because it is deleted. And the record is also deleted from the Book model.

于 2014-08-27T23:46:50.223 回答