[{"id":"djangointermediate-001","courseId":"django-intermediate","domain":"models-and-migrations","topic":"Abstract base classes","prompt":"A CommonInfo model with name and age has abstract = True in its Meta. Student subclasses it and adds home_group. After migrate, which database tables exist for these models?","hint":"Ask which of these classes is ever allowed to get a table.","explain":"Abstract base classes exist to share fields across models at the Python level. Consider how many tables a child model ends up with, and whether the abstract parent is ever stored.","source":"https://docs.djangoproject.com/en/stable/topics/db/models/#abstract-base-classes","interaction":{"type":"single"},"options":[{"id":"a","text":"One table for Student, holding name, age and home_group","why":"An abstract base creates no table, so the child's table gets the inherited fields plus its own."},{"id":"b","text":"Two tables, one for CommonInfo and one for Student","whyNot":"CommonInfo is abstract, so Django never creates a table for it."},{"id":"c","text":"One table for CommonInfo, which Student shares","whyNot":"The abstract parent has no table; each concrete child gets its own."},{"id":"d","text":"Two tables, with Student's holding only home_group","whyNot":"That layout belongs to multi-table inheritance, not to abstract base classes."}],"answer":"a","explanation":"An abstract base class creates no database table; each concrete child class gets one table containing the inherited fields plus its own.","concept":"An abstract base class creates no database table; each concrete child class gets one table containing the inherited fields plus its own.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Abstract parents share fields in Python; only concrete children get tables."]},{"id":"djangointermediate-002","courseId":"django-intermediate","domain":"models-and-migrations","topic":"Proxy models","prompt":"Judge this statement: a proxy model MyPerson subclasses Person with proxy = True. Saving a MyPerson instance stores its row in Person's table, so Person queries return that row.","hint":"Think about whether a proxy changes what gets stored, or only how Python handles the rows.","explain":"A subclass of a concrete model can either get a table of its own or reuse the parent's table. The inheritance style and the Meta options you choose decide which one you get.","source":"https://docs.djangoproject.com/en/stable/topics/db/models/#proxy-models","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"A proxy uses its parent's table, so the saved row is visible to Person queries."},{"id":"b","text":"False","whyNot":"A proxy has no table of its own; it saves data exactly as the original model would."}],"answer":"a","explanation":"A proxy model has no table of its own; it operates on the parent's table, so its rows are the parent's rows.","concept":"A proxy model has no table of its own; it operates on the parent's table, so its rows are the parent's rows.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Proxy models change Python behavior such as methods or ordering, not storage."]},{"id":"djangointermediate-003","courseId":"django-intermediate","domain":"models-and-migrations","topic":"Multi-table inheritance","prompt":"A Place model has name and address. Restaurant subclasses Place, with no abstract flag, and adds cuisine. Which database tables does Django create for Restaurant?","hint":"Think about where the cuisine data has to be stored.","explain":"Subclassing a concrete model is one of several inheritance choices. Think about where a subclass's extra fields need to be stored, and what happens to the parent model's storage.","source":"https://docs.djangoproject.com/en/stable/topics/db/models/#multi-table-inheritance","interaction":{"type":"single"},"options":[{"id":"a","text":"A new table for Restaurant holding cuisine, with Place keeping its own table","why":"Multi-table inheritance gives each subclass its own table for the fields it adds."},{"id":"b","text":"No new table; cuisine is added as a column on Place's table","whyNot":"That is what abstract base classes do; a concrete parent does not absorb its subclass."},{"id":"c","text":"One shared table for both models, with a column that records the class","whyNot":"Django does not store a parent and its child in one table with a class column."},{"id":"d","text":"A new table that copies name and address too, with Place having none","whyNot":"Place is concrete and keeps its table; the subclass's table does not copy the parent's fields."}],"answer":"a","explanation":"Multi-table inheritance creates a new table for each subclass, which stores the fields the subclass adds; the parent keeps its own table.","concept":"Multi-table inheritance creates a new table for each subclass, which stores the fields the subclass adds; the parent keeps its own table.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Concrete subclasses get their own table; abstract parents never do."]},{"id":"djangointermediate-004","courseId":"django-intermediate","domain":"models-and-migrations","topic":"Many-to-many with a through model","prompt":"Membership is a custom through model for Group.members, with date_joined and invite_reason fields. Which TWO statements about this setup are true?","hint":"Think about where details of one relationship can be stored, and how rows get created.","explain":"A many-to-many relationship can be backed by a model you define. Think about where per-relationship details, such as a join date, can live, and how the through model is then used.","source":"https://docs.djangoproject.com/en/stable/topics/db/models/#extra-fields-on-many-to-many-relationships","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"add() and create() work without through_defaults, even when the through model has required fields.","whyNot":"Required fields on the through model need through_defaults when you use add(), create() or set()."},{"id":"b","text":"Extra data such as date_joined belongs on the intermediate model, not on Person or Group.","why":"The intermediate model is where data about each relationship is stored, so extra fields go there."},{"id":"c","text":"With two foreign keys to Group on Membership, Django silently picks one when through_fields is missing.","whyNot":"Django raises a validation error when there are several foreign keys and through_fields is not set."},{"id":"d","text":"A custom through model stops a person joining the same group twice, without any constraint.","whyNot":"Only Django's generated join tables get that uniqueness constraint; a custom through model needs its own."},{"id":"e","text":"You can create memberships by creating Membership instances directly, such as Membership(...).save().","why":"You may prefer to create intermediate-model instances directly, and that works with a through model."},{"id":"f","text":"Django still builds its own join table, so the through model is only a read-only view of it.","whyNot":"A through model replaces the automatic join table; Django does not create a second one."}],"answer":"be","explanation":"A through model holds data about each relationship and replaces Django's automatic join table; you can create its rows directly or through add() and create().","concept":"A through model holds data about each relationship and replaces Django's automatic join table; you can create its rows directly or through add() and create().","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Put per-relationship data on the through model, not on the related models."]},{"id":"djangointermediate-005","courseId":"django-intermediate","domain":"models-and-migrations","topic":"related_name on relations","prompt":"Person.friends is a ManyToManyField('self', through='Friendship'), and both foreign keys on Friendship point at Person. Django can't pick reverse names by itself here. To stop Django creating a backwards relation on one side, what do you set?","hint":"Look at the argument that names the reverse side of a relation.","explain":"Reverse relations are the names Django gives the link from the other side. Think about which argument controls those names, and whether Django can create them at all for this setup.","source":"https://docs.djangoproject.com/en/stable/ref/models/fields/#django.db.models.ForeignKey.related_name","interaction":{"type":"single"},"options":[{"id":"a","text":"related_name='+' on that foreign key","why":"Setting related_name to '+' tells Django not to create a backwards relation for that side."},{"id":"b","text":"symmetrical=False on the ManyToManyField","whyNot":"symmetrical=False adds the reverse descriptor; it does not hide one."},{"id":"c","text":"db_constraint=False on that foreign key","whyNot":"db_constraint controls the database foreign key constraint, not the reverse names."},{"id":"d","text":"related_name=None on that foreign key","whyNot":"None is the default, so Django still builds the default backwards name."}],"answer":"a","explanation":"Setting related_name to '+' on a relation tells Django not to create a backwards relation from the related model.","concept":"Setting related_name to '+' on a relation tells Django not to create a backwards relation from the related model.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Recursive relations through a model need related_name on at least one side."]}]