PythonTutorials.net
Toggle Menu
Home
Online Python Compiler
Tutorials
Django
Flask
Scikit-Learn
NumPy
NLTK
Pillow
Blog
All Posts
Django ORM Mastery
Explore how well you understand Django’s Object-Relational Mapper and query operations.
1. Which Django ORM method is used to retrieve a single object, raising an exception if not found?
filter()
get()
all()
first()
2. Which of the following Django ORM methods return a QuerySet (lazy evaluation, not immediately executing the query)?
filter()
exclude()
all()
count()
3. Django ORM's filter() method returns None if no matching objects are found.
True
False
4. What is the Django ORM method used to create and save a new object in a single step? (full name)
5. Given a model Author with a ForeignKey to Book (on_delete=models.CASCADE), what happens if an Author is deleted?
Related Books are unaffected
Related Books are also deleted
A validation error is raised
The Author's ForeignKey is set to NULL
6. Which of these are valid field types in Django's ORM for storing text data?
CharField
TextField
StringField
TextAreaField
7. The F() expression in Django ORM allows you to perform database-level operations on field values without fetching them into Python.
True
False
8. What is the attribute used to define a one-to-many relationship in Django models (e.g., a Blog having multiple Posts)?
9. Which method is used to perform a SQL JOIN between two models in Django ORM, reducing database queries?
select_related()
filter_related()
join()
prefetch_related()
10. Which of these Django ORM methods return a single value (not a QuerySet)?
count()
exists()
aggregate()
values()
Reset
Answered 0 of 0 — 0 correct