0
0
Djangoframework~10 mins

Async ORM operations in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to asynchronously get all objects from the model.

Django
async def get_all_books():
    books = await Book.objects.[1]().aall()
    return books
Drag options to blanks, or click blank then click option'
Afetch_all
Ball
Call_async
Dget_all
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'all_async()' or 'fetch_all()'.
Forgetting to use 'await' before the ORM call.
2fill in blank
medium

Complete the code to asynchronously get a single object by its primary key.

Django
async def get_book(pk):
    book = await Book.objects.[1](pk=pk)
    return book
Drag options to blanks, or click blank then click option'
Aget_async
Bget
Caget
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Using synchronous 'get()' without 'await'.
Using non-existent methods like 'get_async()'.
3fill in blank
hard

Fix the error in the async save method call.

Django
async def save_book(book):
    await book.[1]()
Drag options to blanks, or click blank then click option'
Asave
Basync_save
Csave_async
Dasave
Attempts:
3 left
💡 Hint
Common Mistakes
Using synchronous 'save()' without 'await'.
Using incorrect method names like 'save_async()'.
4fill in blank
hard

Fill both blanks to asynchronously filter and count objects.

Django
async def count_books_by_author(author_name):
    count = await Book.objects.[1](author=author_name).[2]()
    return count
Drag options to blanks, or click blank then click option'
Afilter
Bcount
Cacount
Dafilter
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'afilter()' which does not exist.
Using synchronous 'count()' without 'await'.
5fill in blank
hard

Fill all three blanks to asynchronously create, update, and save a model instance.

Django
async def create_and_update_book(title, new_title):
    book = await Book.objects.[1](title=title)
    book.title = [2]
    await book.[3]()
Drag options to blanks, or click blank then click option'
Aacreate
Bnew_title
Casave
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using synchronous 'create()' instead of 'acreate()'.
Forgetting to await 'asave()'.
Assigning the wrong variable to book.title.