How to delete a record in Django models?

user426795 picture user426795 · Sep 27, 2010 · Viewed 299.7k times · Source

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?

Answer

Wolph picture Wolph · Sep 27, 2010

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