How to delete a record in Django models?


Question

I want to delete a particular record. Such as

delete from table_name where id = 1;

How can I do this in a django model?

1
214
7/25/2016 8:51:32 AM

There are a couple of ways:

To delete it directly:

SomeModel.objects.filter(id=id).delete()

To delete it from an instance:

instance = SomeModel.objects.get(id=id)
instance.delete()
433
9/27/2010 4:51:50 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon