Contenido del Curso
Django ORM Ninja: Técnicas Avanzadas para Desarrolladores
Django ORM Ninja: Técnicas Avanzadas para Desarrolladores
1. Introduction to Django ORM
2. Models, datatypes, and fields
Deleting
Deleting an object is as straightforward as creating or updating one. You simply define the object to delete and then call the delete()
method.
For example, let's create a test author for deletion:
Note
The
save()
method isn't necessary here ascreate()
already saves the object.
Now, our table has a new instance, and Author.objects.all() will show information about four authors.
The most common approach to delete is to retrieve the instance by its ID and then delete it:
No need to save the changes after deletion.
¿Todo estuvo claro?