Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Deleting | Queries
Django ORM Ninja: Advanced Techniques for Developers
course content

Contenu du cours

Django ORM Ninja: Advanced Techniques for Developers

Django ORM Ninja: Advanced Techniques for Developers

1. Introduction to Django ORM
2. Models, datatypes, and fields
3. Queries
4. Relations
5. Complex Queries
6. Advanced

book
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 as create() 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.

1. How do you delete an object in Django?

2. What happens when you execute Author.objects.get(id=4).delete() in Django?

3. After deleting an object in Django, what is required to reflect this change in the database?

How do you delete an object in Django?

How do you delete an object in Django?

Sélectionnez la réponse correcte

What happens when you execute Author.objects.get(id=4).delete() in Django?

What happens when you execute Author.objects.get(id=4).delete() in Django?

Sélectionnez la réponse correcte

After deleting an object in Django, what is required to reflect this change in the database?

After deleting an object in Django, what is required to reflect this change in the database?

Sélectionnez la réponse correcte

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 6
We're sorry to hear that something went wrong. What happened?
some-alt