Conteúdo do Curso
Django ORM Ninja: Advanced Techniques for Developers
Django ORM Ninja: Advanced Techniques for Developers
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.
Obrigado pelo seu feedback!