0
0
Flaskframework~10 mins

Lazy loading vs eager loading in Flask - Interactive Practice

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

Complete the code to set lazy loading for a relationship in SQLAlchemy.

Flask
posts = db.relationship('Post', lazy=[1])
Drag options to blanks, or click blank then click option'
A'joined'
B'immediate'
C'select'
D'dynamic'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'joined' loads eagerly, not lazily.
Using 'dynamic' returns a query, not a list.
2fill in blank
medium

Complete the code to eagerly load related posts using joined loading.

Flask
user = User.query.options(db.[1]('posts')).first()
Drag options to blanks, or click blank then click option'
Ajoinedload
Blazyload
Cselectinload
Dnoload
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lazyload' does lazy loading, not eager.
Using 'noload' disables loading the relationship.
3fill in blank
hard

Fix the error in the code to eagerly load posts using selectin loading.

Flask
user = User.query.options(db.[1]('posts')).first()
Drag options to blanks, or click blank then click option'
Ajoinedload
Bselectinload
Clazyload
Dnoload
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lazyload' causes lazy loading, not eager.
Using 'noload' skips loading the relationship.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that includes only posts with more than 10 likes.

Flask
popular_posts = {post.id: post for post in user.posts if post.[1] > [2]
Drag options to blanks, or click blank then click option'
Alikes
B10
Ccomments
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'comments' instead of 'likes'.
Using 5 instead of 10 for the threshold.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps post titles to their authors' usernames for posts with more than 100 views.

Flask
post_authors = {post.[1]: post.author.[2] for post in posts if post.[3] > 100}
Drag options to blanks, or click blank then click option'
Atitle
Busername
Cviews
Dlikes
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'likes' instead of 'views' for filtering.
Using 'author' instead of 'username' for the value.