Python – How to delete a record in Django models

djangodjango-modelspython

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?

Best Answer

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()