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

Зміст курсу

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

bookCreate Query

We are already familiar with one type of query – it's the query that retrieves all instances from a single table:

where Author is our model representing the database table, objects is Django's default manager that facilitates query operations, and all() is a method that retrieves all instances from the 'Author' table, akin to the SQL command SELECT * FROM Author. This QuerySet will be used to check the results of our CREATE operations.

If you work inside IDE, you can repeat all these commands in the Python environment activated in the terminal. Write:

Initially, our Author table is empty. Let's add some entries. In Django, we can conveniently create and save a new instance to the database using the create() method:

This single line both creates and saves a new Author object.

After running this, if we execute Author.objects.all(), we'll now see a QuerySet containing our new author.

Let's add two more authors:

Each create() call instantly persists these new instances to the database.

Now, Author.objects.all() returns a list with three instances, reflecting our newly created authors in the database.

1. What does the Django command 'Author.objects.all()' do?
2. In Django, what is 'objects' in 'Author.objects.all()'?
3. What is the result of executing Author.objects.create(first_name="Ronald", last_name="Tolkien")?
What does the Django command 'Author.objects.all()' do?

What does the Django command 'Author.objects.all()' do?

Виберіть правильну відповідь

In Django, what is 'objects' in 'Author.objects.all()'?

In Django, what is 'objects' in 'Author.objects.all()'?

Виберіть правильну відповідь

What is the result of executing Author.objects.create(first_name="Ronald", last_name="Tolkien")?

What is the result of executing Author.objects.create(first_name="Ronald", last_name="Tolkien")?

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 1
some-alt