Skip to content
thesarfo

Note

Deleting Objects

Deleting a single object with delete(), and deleting a whole queryset at once.

views 0

When it comes to deleting objects, we have two options. We can delete a single object or multiple objects.

So if you have a collection, you can delete that collection by using the ‘.delete’ method.

def say_hello(request):
'''deletes a single object'''
collection = Collection(pk=11)
collection.delete()
pass

To delete multiple objects, first we need to get a queryset. For instasnce, lets say we want to delete all objects that have an id greater than 5

Collection.objects.filter(id___gt=5).delete()
# this returns a queryset, and then we can delete the queryset