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.
Which Django class should a model normally inherit from?
Not quite. Try another option.
Answer: models.Model
A Django model inherits from django.db.models.Model, usually referenced as models.Model.
Question 2 of 60 · Creating models · Easy
Which field is commonly used to store a short text value in a Django model?
Not quite. Try another option.
Answer: models.CharField
CharField stores short strings and normally requires a max_length value.
Question 3 of 60 · Working with Migrations · Easy
Which command creates migration files after model changes?
Not quite. Try another option.
Answer: python manage.py makemigrations
makemigrations detects model changes and creates migration files for them.
Question 4 of 60 · Working with Migrations · Easy
Which command applies pending migrations to the database?
Not quite. Try another option.
Answer: python manage.py migrate
migrate applies migration operations and updates the database schema.
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?
Not quite. Try another option.
Answer: Book.objects.create(title="Python")
objects.create() constructs a model object and immediately saves it to the database.
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?
Not quite. Try another option.
Answer: save()
Calling save() on a model instance writes its current field values to the database.
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?
Not quite. Try another option.
Answer: delete()
Calling delete() on a model instance removes its corresponding database record.
Question 8 of 60 · Using Object Relational Mapping (ORM) · Easy
What is the main purpose of Django's Object Relational Mapping (ORM)?
Not quite. Try another option.
Answer: To work with database records using Python objects
The ORM lets developers query and modify database data through Python classes and objects.
Question 9 of 60 · Using Object Relational Mapping (ORM) · Easy
Which ORM expression retrieves all objects from the Book model?
Not quite. Try another option.
Answer: Book.objects.all()
objects.all() returns a QuerySet containing all records for the model.
Question 10 of 60 · Models using Foreign Keys · Easy
Which Django model field defines a many-to-one relationship?
Not quite. Try another option.
Answer: models.ForeignKey
ForeignKey creates a many-to-one relationship between two Django models.
Question 11 of 60 · Models using Foreign Keys · Easy
What does on_delete=models.CASCADE do in a foreign key relationship?
Not quite. Try another option.
Answer: Deletes related child records with the parent
CASCADE deletes dependent records when the referenced parent record is deleted.
Question 12 of 60 · Django Admin · Easy
Which statement registers the Book model with the Django admin site?
Not quite. Try another option.
Answer: admin.site.register(Book)
Registering a model with admin.site.register() makes it manageable through Django Admin.
Question 13 of 60 · Django Admin · Easy
What is the default URL path commonly used to access Django Admin?
Not quite. Try another option.
Answer: /admin/
Django projects commonly map the built-in admin site to the /admin/ URL path.
Question 14 of 60 · Adding groups and users · Easy
Which command creates an administrator account for Django Admin?
Not quite. Try another option.
Answer: python manage.py createsuperuser
The createsuperuser command creates an account with full administrative privileges.
Question 15 of 60 · Adding groups and users · Easy
Why are groups used in Django's authentication system?
Not quite. Try another option.
Answer: To assign shared permissions to multiple users
Groups make it easier to grant the same set of permissions to several users.
Question 16 of 60 · Users and Permissions · Easy
What does a Django permission control?
Not quite. Try another option.
Answer: Which actions a user may perform
Permissions determine whether a user can perform actions such as adding, changing, viewing, or deleting objects.
Question 17 of 60 · Users and Permissions · Easy
Which user attribute usually allows access to the Django admin site?
Not quite. Try another option.
Answer: is_staff
A user generally needs is_staff=True to log in to the Django admin site.
Question 18 of 60 · Database configuration · Easy
In which Django settings variable is database configuration stored?
Not quite. Try another option.
Answer: DATABASES
The DATABASES dictionary in settings.py contains database connection settings.
Question 19 of 60 · Configuring and setting up database connection · Easy
Which database engine is used by a newly created Django project by default?
Not quite. Try another option.
Answer: SQLite
New Django projects are configured to use SQLite by default because it requires minimal setup.
Question 20 of 60 · Configuring and setting up database connection · Easy
Which database setting specifies the Django backend to use?
Not quite. Try another option.
Answer: ENGINE
The ENGINE setting identifies the database backend, such as SQLite, PostgreSQL, or MySQL.
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?
blank=True allows the field to be empty during form validation. String-based fields normally store an omitted value as an empty string.
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?
price__lt=100 means below 100, while stock__gte=1 means the stock value is at least 1.
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?
Not quite. Try another option.
Answer: Book.objects.select_related("publisher")
select_related() retrieves single-valued relationships such as foreign keys using a SQL join, avoiding a separate publisher query for each book.
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?
admin.site.register() accepts the model first and its optional ModelAdmin class second.
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?
Not quite. Try another option.
Answer: list_display = ("name", "price", "stock")
list_display controls the columns shown for each object on the Django admin change list page.
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?
Not quite. Try another option.
Answer: user = User.objects.create_user("maya"); group, _ = Group.objects.get_or_create(name="Editors"); user.groups.add(group)
create_user() creates a normal user, get_or_create() safely obtains the group, and user.groups.add() establishes the membership.
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?
Not quite. Try another option.
Answer: It hashes the password before storing it
create_user() processes the password with Django's password hashing system instead of storing the raw value.
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?
Not quite. Try another option.
Answer: user.has_perm("blog.change_article")
Django permission strings use the format app_label.permission_codename, and the standard change codename is change_modelname.
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?
Not quite. Try another option.
Answer: True, because group permissions are included
Django's permission checks combine permissions assigned directly to the user with permissions inherited from the user's groups.
Question 37 of 60 · Database configuration · Medium
Which DATABASES setting selects Django's built-in SQLite backend?
Not quite. Try another option.
Answer: "ENGINE": "django.db.backends.sqlite3"
django.db.backends.sqlite3 is Django's backend identifier for SQLite databases.
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?
Not quite. Try another option.
Answer: BASE_DIR / "db.sqlite3"
The / operator joins pathlib.Path objects with path components, producing the intended database file path.
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?
Not quite. Try another option.
Answer: A PostgreSQL database adapter such as psycopg
Django requires a compatible database adapter, such as psycopg, to establish PostgreSQL connections.
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?
Not quite. Try another option.
Answer: HOST and PORT
HOST specifies the database server's network address, and PORT specifies the port on which that server accepts connections.
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?
The callable uuid.uuid4 must be passed without invoking it. Django calls it separately whenever a default value is required.
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?
A conditional UniqueConstraint enforces uniqueness only for rows satisfying cancelled=False. An index alone does not enforce uniqueness.
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?
Not quite. Try another option.
Answer: Add the field as nullable, populate it with RunPython, then alter it to non-nullable and unique
A staged schema-data-schema migration avoids assigning the same default to existing rows and permits values to be populated before enforcing constraints.
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?
Not quite. Try another option.
Answer: It retrieves the historical model state corresponding to that migration
Migration code must operate against the model definition valid at that point in migration history. Direct imports expose the current model and can break older migrations.
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?
Not quite. Try another option.
Answer: python manage.py migrate --fake-initial
--fake-initial detects existing tables or columns for initial migrations and can mark those migrations as applied without recreating the schema.
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?
QuerySet.update() issues a direct SQL update. It bypasses model save() methods, field pre_save() processing, and save signals.
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()?
Not quite. Try another option.
Answer: The override is skipped, but Django still sends deletion signals for deleted model instances
Bulk queryset deletion does not call each model's overridden delete() method. Django's deletion collector still handles cascades and sends pre_delete and post_delete signals.
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?
An F() expression performs the arithmetic in SQL using the current stored value, avoiding the stale application-side read used by ordinary read-modify-write code.
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?
select_related() joins single-valued relationships such as foreign keys, while prefetch_related() performs separate batched queries for many-to-many relationships.
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?
annotate() adds an aggregate value to each customer row, after which the alias can be filtered. aggregate() instead returns one summary dictionary for the entire queryset.
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?
PROTECT raises ProtectedError when deletion would remove a referenced invoice. DO_NOTHING delegates behavior to the database and does not itself provide Django-level protection.
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?
Not quite. Try another option.
Answer: The target field must enforce uniqueness
The referenced field must uniquely identify one target row, typically through unique=True or an equivalent unconditional uniqueness constraint.
Question 53 of 60 · Models using Foreign Keys · Hard
What is the effect of defining related_name='+' on a ForeignKey from Comment to Article?
Not quite. Try another option.
Answer: Django creates no reverse relation from Article to Comment
A related_name ending in + suppresses creation of the reverse accessor and reverse query name on the related model.
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?
Not quite. Try another option.
Answer: list_select_related = ('customer',)
list_select_related joins the foreign-key target into the changelist query. raw_id_fields and autocomplete_fields optimize form widgets, not changelist row access.
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?
Not quite. Try another option.
Answer: Grant view_contract and deny the add, change, and delete permissions
Admin access is controlled by model permissions and permission hooks. Read-only widgets affect form editing but are not a substitute for denying change, add, and delete authorization.
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?
get_user_model() returns the active user class, and create_user() uses the manager's user-creation logic, including password hashing.
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?
Not quite. Try another option.
Answer: The user has both change_report and delete_report
With Django's default permission backend, effective permissions are the union of direct user permissions and permissions inherited from all groups.
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?
Not quite. Try another option.
Answer: During the post_migrate processing triggered by migrate
Django creates default and custom model permissions through a post_migrate handler after migrations are applied.
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?
Not quite. Try another option.
Answer: It returns False because ModelBackend does not implement object-level permissions
The default ModelBackend handles global model permissions but does not grant permissions when an object is supplied. Object-level checks require a supporting backend.
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?
Not quite. Try another option.
Answer: Migration operations for that model are skipped on analytics
allow_migrate() controls whether migration operations are permitted on a particular database. Read and write routing is handled separately by db_for_read() and db_for_write().
That's unit 5
Answer a few questions and your score shows up here.
Nearly through. Did unit 5 of INT253 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 5 of INT253 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.