Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 5 MCQs Models and Migrations and Django Admin

INT253 — Web Development In Python Using Django 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 Creating models Easy

    Which Django class should a model normally inherit from?

  2. Question 2 of 60 Creating models Easy

    Which field is commonly used to store a short text value in a Django model?

  3. Question 3 of 60 Working with Migrations Easy

    Which command creates migration files after model changes?

  4. Question 4 of 60 Working with Migrations Easy

    Which command applies pending migrations to the database?

  5. Question 5 of 60 Using the Django Shell to Explore Models (Insert, Update and Delete) Easy

    Which ORM statement creates and saves a new Book object in one step?

  6. Question 6 of 60 Using the Django Shell to Explore Models (Insert, Update and Delete) Easy

    After changing an object's field in the Django shell, which method saves the change?

  7. Question 7 of 60 Using the Django Shell to Explore Models (Insert, Update and Delete) Easy

    Which method deletes a model instance from the database?

  8. Question 8 of 60 Using Object Relational Mapping (ORM) Easy

    What is the main purpose of Django's Object Relational Mapping (ORM)?

  9. Question 9 of 60 Using Object Relational Mapping (ORM) Easy

    Which ORM expression retrieves all objects from the Book model?

  10. Question 10 of 60 Models using Foreign Keys Easy

    Which Django model field defines a many-to-one relationship?

  11. Question 11 of 60 Models using Foreign Keys Easy

    What does on_delete=models.CASCADE do in a foreign key relationship?

  12. Question 12 of 60 Django Admin Easy

    Which statement registers the Book model with the Django admin site?

  13. Question 13 of 60 Django Admin Easy

    What is the default URL path commonly used to access Django Admin?

  14. Question 14 of 60 Adding groups and users Easy

    Which command creates an administrator account for Django Admin?

  15. Question 15 of 60 Adding groups and users Easy

    Why are groups used in Django's authentication system?

  16. Question 16 of 60 Users and Permissions Easy

    What does a Django permission control?

  17. Question 17 of 60 Users and Permissions Easy

    Which user attribute usually allows access to the Django admin site?

  18. Question 18 of 60 Database configuration Easy

    In which Django settings variable is database configuration stored?

  19. Question 19 of 60 Configuring and setting up database connection Easy

    Which database engine is used by a newly created Django project by default?

  20. Question 20 of 60 Configuring and setting up database connection Easy

    Which database setting specifies the Django backend to use?

  21. Question 21 of 60 Creating models Medium

    A Product model has a description field that should be optional in forms but stored as an empty string rather than NULL. Which field definition is most appropriate?

  22. Question 22 of 60 Creating models Medium

    A model should automatically record when each object was first created, and the value must not change on later saves. Which field definition should be used?

  23. Question 23 of 60 Working with Migrations Medium

    After adding a field to a Django model, which sequence correctly creates and applies the required database change?

  24. Question 24 of 60 Working with Migrations Medium

    A developer wants to preview the SQL that Django will execute for migration 0003 in the store app. Which command should be used?

  25. Question 25 of 60 Using the Django Shell to Explore Models (Insert, Update and Delete) Medium

    In the Django shell, which statement creates and immediately saves a new Book with the title Django Basics?

  26. Question 26 of 60 Using the Django Shell to Explore Models (Insert, Update and Delete) Medium

    Which Django shell operation updates the status of every Order currently marked pending without loading each order individually?

  27. Question 27 of 60 Using Object Relational Mapping (ORM) Medium

    Given a Product model with price and stock fields, which query returns products costing less than 100 and having at least one item in stock?

  28. Question 28 of 60 Using Object Relational Mapping (ORM) Medium

    A page displays many books and accesses book.publisher.name for each result. Which query most directly reduces repeated database queries when publisher is a ForeignKey?

  29. Question 29 of 60 Models using Foreign Keys Medium

    An Article has a foreign key to Author. Articles must remain when an author is deleted, but their author value should become NULL. Which configuration is required?

  30. Question 30 of 60 Models using Foreign Keys Medium

    The Book.author foreign key defines related_name="books". If author is an Author instance, which expression retrieves that author's books?

  31. Question 31 of 60 Django Admin Medium

    A ProductAdmin class has been defined for the Product model. Which statement correctly registers the model with that custom admin class?

  32. Question 32 of 60 Django Admin Medium

    An administrator needs to see the name, price, and stock values as columns on the product list page. Which ModelAdmin setting provides this behavior?

  33. Question 33 of 60 Adding groups and users Medium

    In Python code, which sequence correctly creates a user named maya, creates or retrieves the Editors group, and adds the user to it?

  34. Question 34 of 60 Adding groups and users Medium

    Why should User.objects.create_user() normally be used instead of User.objects.create() when creating a user with a password?

  35. Question 35 of 60 Users and Permissions Medium

    For an app labeled blog with a model named Article, which call checks whether a user has the standard permission to change articles?

  36. Question 36 of 60 Users and Permissions Medium

    A user receives change_article permission through the Editors group but has no direct user permissions. What should user.has_perm("blog.change_article") return for an active user?

  37. Question 37 of 60 Database configuration Medium

    Which DATABASES setting selects Django's built-in SQLite backend?

  38. Question 38 of 60 Database configuration Medium

    A project uses SQLite and should keep its database file at the project base directory as db.sqlite3. Which NAME value is appropriate when BASE_DIR is a pathlib.Path?

  39. Question 39 of 60 Configuring and setting up database connection Medium

    A Django project is being changed from SQLite to PostgreSQL. Besides updating DATABASES, which dependency is normally required so Python can communicate with PostgreSQL?

  40. Question 40 of 60 Configuring and setting up database connection Medium

    A PostgreSQL server is running on another machine and listens on port 5433. Which Django database settings identify where the connection should be made?

  41. Question 41 of 60 Creating models Hard

    A Document model must generate a new UUID for every inserted row. Which field declaration correctly avoids sharing a single value across instances?

  42. Question 42 of 60 Creating models Hard

    A Booking model must prevent two active bookings from having the same room and date, while allowing any number of cancelled duplicates. Which Meta.constraints entry best expresses this rule on a database that supports partial unique constraints?

  43. Question 43 of 60 Working with Migrations Hard

    A populated table receives a new non-nullable slug field whose value must be uniquely derived from each existing row. Which migration strategy is safest?

  44. Question 44 of 60 Working with Migrations Hard

    Inside a RunPython data migration, why should code normally use apps.get_model('store', 'Product') instead of importing Product directly?

  45. Question 45 of 60 Working with Migrations Hard

    An application is introduced into a project whose database already contains tables matching the app's initial migration. Which command is specifically designed to mark that initial migration as applied after verifying compatible table names?

  46. Question 46 of 60 Using the Django Shell to Explore Models (Insert, Update and Delete) Hard

    In the Django shell, which operation updates every matching row efficiently but does not call each instance's save() method or emit pre_save and post_save signals?

  47. Question 47 of 60 Using the Django Shell to Explore Models (Insert, Update and Delete) Hard

    Suppose Order.delete() is overridden to write an audit entry. What happens when the shell executes Order.objects.filter(expired=True).delete()?

  48. Question 48 of 60 Using Object Relational Mapping (ORM) Hard

    Two concurrent requests increment the same Counter.value. Which ORM statement performs the increment in the database and best avoids a lost update caused by read-modify-write logic?

  49. Question 49 of 60 Using Object Relational Mapping (ORM) Hard

    A page lists books, accesses each book's single publisher, and iterates over each book's many-to-many authors. Which queryset most directly prevents the corresponding N+1 query patterns?

  50. Question 50 of 60 Using Object Relational Mapping (ORM) Hard

    A report must return customers whose total paid invoice amount exceeds 10,000, including the calculated total. Which ORM pattern correctly filters on the aggregate?

  51. Question 51 of 60 Models using Foreign Keys Hard

    An Invoice must never be deleted automatically or manually while Payment rows still reference it. Which ForeignKey deletion behavior most directly enforces this rule through Django's deletion collector?

  52. Question 52 of 60 Models using Foreign Keys Hard

    A ForeignKey uses to_field='code' to reference a field other than the target model's primary key. Which target-field property is generally required for an ordinary many-to-one relationship?

  53. Question 53 of 60 Models using Foreign Keys Hard

    What is the effect of defining related_name='+' on a ForeignKey from Comment to Article?

  54. Question 54 of 60 Django Admin Hard

    An admin changelist displays order.customer.email for hundreds of orders and currently performs one additional customer query per row. Which ModelAdmin setting is the most direct optimization?

  55. Question 55 of 60 Django Admin Hard

    A staff member may view all Contract records but must not add, change, or delete them in the admin. Which approach most directly enforces this at the ModelAdmin authorization layer?

  56. Question 56 of 60 Adding groups and users Hard

    A project uses a swappable custom user model. Which code is safest for creating a regular user programmatically while ensuring the configured model and password hashing logic are used?

  57. Question 57 of 60 Adding groups and users Hard

    A user has change_report directly, belongs to a group with delete_report, and belongs to another group with no permissions. Assuming the default ModelBackend, the user is active and not a superuser. What is the effective result?

  58. Question 58 of 60 Users and Permissions Hard

    A custom permission publish_article is added to Article.Meta.permissions. When is the corresponding auth_permission record normally created?

  59. Question 59 of 60 Users and Permissions Hard

    Code calls user.has_perm('news.change_article', article) using only Django's default ModelBackend. The user has the global change_article permission but no object-permission backend is installed. What should be expected for this object-specific check?

  60. Question 60 of 60 Database configuration Hard

    A Django project has default and analytics databases. A router's allow_migrate(db, app_label, model_name, **hints) returns False for the analytics database and a reporting model. What is the intended effect?

That's unit 5

Answer a few questions and your score shows up here.