Bird
Raised Fist0
Djangoframework~20 mins

Registering models in admin in Django - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Django Admin Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output when accessing the Django admin after registering a model incorrectly?

Consider the following Django admin registration code:

from django.contrib import admin
from .models import Book

admin.site.register(Book())

What happens when you try to access the Django admin page for the Book model?

Django
from django.contrib import admin
from .models import Book

admin.site.register(Book())
ARaises a TypeError because an instance is passed instead of the model class.
BThe admin page shows the Book model list correctly.
CThe admin page shows but with no data listed.
DRaises an ImportError due to wrong import syntax.
Attempts:
2 left
💡 Hint

Remember that admin.site.register() expects a model class, not an instance.

📝 Syntax
intermediate
2:00remaining
Which code correctly registers multiple models in Django admin?

You want to register two models, Author and Publisher, in the Django admin. Which of the following code snippets is correct?

Aadmin.site.register(Author, Publisher)
Badmin.site.register({Author, Publisher})
Cadmin.site.register(Author); admin.site.register(Publisher)
Dadmin.site.register([Author, Publisher])
Attempts:
2 left
💡 Hint

Think about how to register multiple models separately or together.

🔧 Debug
advanced
2:00remaining
Why does this custom admin class not apply to the model in Django admin?

Given this code:

from django.contrib import admin
from .models import Article

class ArticleAdmin(admin.ModelAdmin):
    list_display = ('title', 'published_date')

admin.site.register(Article)

Why does the admin page not show the custom list display?

Django
from django.contrib import admin
from .models import Article

class ArticleAdmin(admin.ModelAdmin):
    list_display = ('title', 'published_date')

admin.site.register(Article)
ABecause admin.site.register requires a decorator.
BBecause list_display is not a valid attribute for ModelAdmin.
CBecause the Article model is not imported correctly.
DBecause the admin class ArticleAdmin was not passed to admin.site.register.
Attempts:
2 left
💡 Hint

Check how the admin class is linked to the model registration.

❓ state_output
advanced
2:00remaining
What is the effect of this admin registration with a decorator?

Consider this Django admin code:

from django.contrib import admin
from .models import Event

@admin.register(Event)
class EventAdmin(admin.ModelAdmin):
    list_display = ('name', 'date')

What happens when you access the admin page for Event?

Django
from django.contrib import admin
from .models import Event

@admin.register(Event)
class EventAdmin(admin.ModelAdmin):
    list_display = ('name', 'date')
AThe Event model is registered with the custom EventAdmin showing name and date columns.
BThe Event model is registered but uses default admin settings ignoring list_display.
CRaises a SyntaxError because decorators cannot be used with admin classes.
DThe Event model is not registered at all.
Attempts:
2 left
💡 Hint

Think about what the @admin.register() decorator does.

🧠 Conceptual
expert
2:00remaining
What error occurs if you register the same model twice with different admin classes?

Given this code snippet:

from django.contrib import admin
from .models import Product

class ProductAdmin1(admin.ModelAdmin):
    list_display = ('name',)

class ProductAdmin2(admin.ModelAdmin):
    list_display = ('price',)

admin.site.register(Product, ProductAdmin1)
admin.site.register(Product, ProductAdmin2)

What happens when Django starts?

Django
from django.contrib import admin
from .models import Product

class ProductAdmin1(admin.ModelAdmin):
    list_display = ('name',)

class ProductAdmin2(admin.ModelAdmin):
    list_display = ('price',)

admin.site.register(Product, ProductAdmin1)
admin.site.register(Product, ProductAdmin2)
ARaises a SyntaxError due to duplicate registration.
BRaises django.contrib.admin.sites.AlreadyRegistered error.
CBoth admin classes are merged and applied.
DThe second registration overrides the first without error.
Attempts:
2 left
💡 Hint

Think about how Django admin handles multiple registrations of the same model.

Practice

(1/5)
1. What is the main purpose of registering a model in Django admin using admin.site.register(ModelName)?
easy
A. To make the model manageable through the Django admin web interface
B. To create a new database table for the model
C. To automatically generate API endpoints for the model
D. To enable model validation during form submission

Solution

  1. Step 1: Understand the role of Django admin

    Django admin provides a web interface to manage database models easily without coding forms manually.
  2. Step 2: Identify what registering a model does

    Registering a model with admin.site.register(ModelName) makes it appear in the admin interface for management.
  3. Final Answer:

    To make the model manageable through the Django admin web interface -> Option A
  4. Quick Check:

    Registering model = Manage in admin [OK]
Hint: Registering means showing model in admin panel [OK]
Common Mistakes:
  • Confusing registration with database table creation
  • Thinking registration creates API endpoints
  • Assuming registration validates forms automatically
2. Which of the following is the correct syntax to register a model named Book in Django admin inside admin.py?
easy
A. admin.site.register(Book)
B. site.admin.register(Book)
C. register.admin(Book)
D. admin.register(Book)

Solution

  1. Step 1: Recall the Django admin registration syntax

    The correct syntax uses admin.site.register(ModelName) to register models.
  2. Step 2: Match the syntax with options

    Only admin.site.register(Book) matches the correct pattern exactly.
  3. Final Answer:

    admin.site.register(Book) -> Option A
  4. Quick Check:

    Correct syntax = admin.site.register(Model) [OK]
Hint: Remember: admin.site.register(Model) is correct [OK]
Common Mistakes:
  • Using admin.register instead of admin.site.register
  • Swapping order of site and admin
  • Using incorrect module names
3. Given this admin.py code:
from django.contrib import admin
from .models import Author

admin.site.register(Author)

What will happen when you access the Django admin site?
medium
A. The Author model will not appear in admin because it is not imported
B. You will see an interface to add, edit, and delete Author records
C. You will get a syntax error because of missing parentheses
D. The admin site will crash due to missing admin class

Solution

  1. Step 1: Check the import and registration

    The Author model is imported and registered correctly with admin.site.register(Author).
  2. Step 2: Understand admin behavior

    Registering the model shows it in admin with default interface to add, edit, delete records.
  3. Final Answer:

    You will see an interface to add, edit, and delete Author records -> Option B
  4. Quick Check:

    Registered model = visible in admin [OK]
Hint: Registered model appears in admin with default UI [OK]
Common Mistakes:
  • Assuming missing admin class causes crash
  • Thinking import is missing when it is present
  • Confusing syntax error with correct code
4. Identify the error in this admin.py snippet:
from django.contrib import admin
from .models import Publisher

admin.site.register(Publisher())
medium
A. Using admin.register instead of admin.site.register
B. Missing import statement for admin
C. Calling Publisher as a function instead of passing the class
D. No error, code is correct

Solution

  1. Step 1: Analyze the registration argument

    The code calls Publisher() which creates an instance, but registration needs the class itself.
  2. Step 2: Understand correct usage

    Correct usage is admin.site.register(Publisher) without parentheses.
  3. Final Answer:

    Calling Publisher as a function instead of passing the class -> Option C
  4. Quick Check:

    Register model class, not instance [OK]
Hint: Register model class, not instance (no parentheses) [OK]
Common Mistakes:
  • Adding parentheses after model name
  • Forgetting to import admin
  • Confusing admin.site.register with admin.register
5. You want to customize the admin interface for a model Article to display the title and published_date columns in the list view. Which is the correct way to register this model with customization?
hard
A. admin.site.register(Article) admin.list_display = ['title', 'published_date']
B. admin.site.register(Article, list_display=['title', 'published_date'])
C. admin.site.register(Article) Article.list_display = ['title', 'published_date']
D. class ArticleAdmin(admin.ModelAdmin): list_display = ('title', 'published_date') admin.site.register(Article, ArticleAdmin)

Solution

  1. Step 1: Understand how to customize admin list display

    Customization requires defining a ModelAdmin subclass with list_display attribute.
  2. Step 2: Register model with the custom admin class

    Pass the ModelAdmin subclass as the second argument to admin.site.register().
  3. Final Answer:

    Define ArticleAdmin with list_display and register it with Article -> Option D
  4. Quick Check:

    Custom admin = ModelAdmin subclass + register [OK]
Hint: Use ModelAdmin subclass with list_display, then register [OK]
Common Mistakes:
  • Trying to pass list_display directly to register
  • Setting list_display on model instance or admin module
  • Not defining a ModelAdmin subclass for customization
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard