db.models.fields.related.RelatedManager.clear()

clear()

Removes all objects from the related object set:

>>> b = Blog.objects.get(id=1)
>>> b.entry_set.clear()

Note this doesn’t delete the related objects – it just disassociates them.

Just like remove(), clear() is only available on ForeignKeys where null=True and it also accepts the bulk keyword argument.

doc_Django
2016-10-09 18:35:35
Comments
Leave a Comment

Please login to continue.