0
0
Flaskframework~10 mins

Why ORM simplifies database access in Flask - Test Your Understanding

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

Complete the code to import the ORM base class from SQLAlchemy.

Flask
from flask_sqlalchemy import [1]
Drag options to blanks, or click blank then click option'
ADatabase
BFlask
CSQLAlchemy
DModel
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Flask' instead of 'SQLAlchemy' will cause import errors.
2fill in blank
medium

Complete the code to define a model class for a user table.

Flask
class User(db.[1]):
Drag options to blanks, or click blank then click option'
AModel
BTable
CBase
DEntity
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Table' or 'Base' will cause errors because they are not the correct base class.
3fill in blank
hard

Fix the error in the column definition to specify a primary key.

Flask
id = db.Column(db.Integer, [1]=True)
Drag options to blanks, or click blank then click option'
Amain_key
Bprimary
Ckey_primary
Dprimary_key
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'primary' or 'key_primary' will cause runtime errors.
4fill in blank
hard

Fill both blanks to create a query that gets all users with age greater than 18.

Flask
adults = User.query.filter(User.age [1] [2]).all()
Drag options to blanks, or click blank then click option'
A>
B18
C<
D21
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or 21 will give wrong results or no results.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps usernames to emails for users older than 20.

Flask
user_dict = {user.[1]: user.[2] for user in users if user.[3] > 20}
Drag options to blanks, or click blank then click option'
Ausername
Bemail
Cage
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' instead of 'username' or wrong filter attribute causes errors.