Deleting objects

If you want to delete an object, you can do it from the object instance using the delete() method:

post = Post.objects.get(id=1)post.delete()
Note that deleting objects will also delete any dependent relationships for ForeignKey objects defined with on_delete set to CASCADE.

Get Django 2 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.