โ† All Django Flashcard Decks

Django Models & ORM Flashcards

6 cards from real Django practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 6 Django Models & ORM flashcards as text
  1. Which Django command applies pending database migrations?

    Answer: python manage.py migrate

    migrate applies all pending migration files to synchronize the database schema with the current state of your models.

  2. What is a QuerySet in Django?

    Answer: A lazy collection of database objects that can be filtered and chained

    A QuerySet represents a collection of database rows that can be filtered, ordered, and evaluated lazily when the data is actually needed.

  3. Which method would you call to create and save a new model instance in one step?

    Answer: Model.objects.create()

    Model.objects.create() instantiates the model and calls save() in a single database operation.

  4. What does `select_related()` do in a Django QuerySet?

    Answer: Performs a SQL JOIN to fetch related objects in a single query

    select_related() follows ForeignKey and OneToOneField relationships and performs a SQL JOIN, reducing the number of database queries.

  5. Which lookup suffix checks if a field value is in a given list in Django ORM?

    Answer: __in

    The __in lookup filters objects whose field value is contained in the provided list, generating a SQL IN clause.

  6. What is the purpose of `prefetch_related()` in Django ORM?

    Answer: Fetches many-to-many and reverse ForeignKey relations in separate optimized queries

    prefetch_related() does separate queries for each relationship and performs the joining in Python, which is optimal for many-to-many and reverse FK lookups.

Written and edited by , founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy

Django Models & ORM Flashcards โ€” Django Study Cards with Answers