โ† 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 ORM method retrieves a single object and raises an exception if not found?

    Answer: get()

    The get() method returns a single object matching the query and raises DoesNotExist if no match or MultipleObjectsReturned if more than one match.

  2. What does the `on_delete=models.CASCADE` argument do in a ForeignKey field?

    Answer: Deletes related objects when the referenced object is deleted

    CASCADE causes Django to automatically delete all objects that have a ForeignKey pointing to the deleted object.

  3. Which field type would you use to store a many-to-many relationship in a Django model?

    Answer: ManyToManyField

    ManyToManyField creates a junction table in the database to store many-to-many relationships between two models.

  4. What is the purpose of Django's `Meta` class inside a model?

    Answer: To define model-level options like ordering and table name

    The inner Meta class allows you to set model-level metadata such as ordering, verbose_name, db_table, and unique_together constraints.

  5. Which ORM method returns a QuerySet of all objects matching a condition without raising exceptions?

    Answer: filter()

    filter() returns a QuerySet containing all objects that match the given lookup parameters, returning an empty QuerySet if none are found.

  6. What does the `__str__` method on a Django model do?

    Answer: Returns a human-readable string representation of the model instance

    Defining __str__ on a model controls how an instance is displayed as a string, which is used in the Django admin and shell.

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