Question 3Easy
Which command creates a user who can log in to the admin site with all permissions?
- python manage.py createsuperuser
- python manage.py addadmin
- python manage.py createadmin
- python manage.py adduser --admin
Answer: A. python manage.py createsuperuser
Explanation
createsuperuser sets is_staff and is_superuser.
Step-by-step solution
- Createsuperuser command sets is_staff and is_superuser.
- These flags allow login to admin site with all permissions.
- Other commands do not set both flags correctly.
- Thus, createsuperuser is the correct command.
- Final answer: python manage.py createsuperuser.
Why the other options are wrong
- B. addadmin is not a Django command; createsuperuser sets the staff and superuser flags.
- C. createadmin is not a built-in Django command; the built-in one is createsuperuser.
- D. adduser has no
--admin flag in Django; a superuser is made with createsuperuser.
Tip: Remember: createsuperuser gives all permissions for Django admin.
Question 4Easy
Which command creates an admin login?
- python manage.py createadmin
- python manage.py createsuperuser
- python manage.py adduser
- python manage.py makeuser
Answer: B. python manage.py createsuperuser
Explanation
It prompts for username, email and password.
Step-by-step solution
- Run command.
- Visit /admin/.
Why the other options are wrong
- A.
python manage.py createadmin is not a Django management command; the correct choice is python manage.py createsuperuser. - C.
python manage.py adduser is not a Django management command; the correct choice is python manage.py createsuperuser. - D.
python manage.py makeuser is not a Django management command; the correct choice is python manage.py createsuperuser.
Question 5Easy
Which file in an app is conventionally used to register models with the admin site?
- admin.py
- models.py
- apps.py
- views.py
Answer: A. admin.py
Explanation
Use admin.site.register or the @admin.register decorator.
Step-by-step solution
- Admin site registration uses the admin module in Django.
- The admin.py file contains functions to register models with the admin site.
- Using admin.site.register is the standard way to link models to the admin interface.
- This makes the model visible in the Django admin panel for management.
- Therefore, the correct file is admin.py.
Why the other options are wrong
- B. models.py defines the data models; it is not where admin registration is conventionally done.
- C. apps.py holds the app's configuration class, not admin registration.
- D. views.py holds request handling, not admin registration.
Tip: Remember: admin.py is where you register models for the Django admin.
Question 6Medium
Which ModelAdmin option controls which fields appear as columns in the change list?
- fields
- list_filter
- display_columns
- list_display
Answer: D. list_display
Explanation
list_display takes field or method names.
Step-by-step solution
- List_display controls columns in change list.
- It uses field or method names.
- Option D is list_display.
- Final answer: D (list_display).
Why the other options are wrong
- A. fields sets the form layout for editing, not the change list columns.
- B. list_filter adds a sidebar of filters to the change list; it does not choose the columns.
- C. display_columns is not a ModelAdmin option; the option is list_display.
Tip: Remember: list_display = columns in admin change list.
Question 7Medium
Which attribute lets you edit related child rows on the parent's admin page?
- children
- related_edit
- nested
- inlines (TabularInline or StackedInline)
Answer: D. inlines (TabularInline or StackedInline)
Explanation
Define an Inline class with model and add it to ModelAdmin.inlines.
Step-by-step solution
- Define inline.
- Attach.
Why the other options are wrong
- A.
children is not a valid option here; the correct choice is inlines (TabularInline or StackedInline). - B.
related_edit is not a valid option here; the correct choice is inlines (TabularInline or StackedInline). - C.
nested is not a valid option here; the correct choice is inlines (TabularInline or StackedInline).