Recall & Review
beginner
What is the purpose of
list_display in Django admin?The
list_display attribute in Django admin defines which model fields are shown as columns in the admin list view. It helps customize the display of records for easier management.Click to reveal answer
intermediate
How do you add a custom method to
list_display in Django admin?You define a method inside the admin class that returns a value, then add the method name as a string to <code>list_display</code>. This method can show computed or related data in the list view.Click to reveal answer
beginner
True or False: You can include model fields and methods in
list_display.True. <code>list_display</code> can include both model fields and methods defined in the admin class to customize the columns shown.Click to reveal answer
intermediate
What happens if you include a method in
list_display that does not return a value?If the method returns None or does not return anything, the column will appear empty in the admin list view. Always return a string or value to display.
Click to reveal answer
advanced
How can you make a column in
list_display sortable?To make a column sortable, the field or method name in
list_display should correspond to a model field or have an admin_order_field attribute set to a model field name.Click to reveal answer
What does
list_display control in Django admin?✗ Incorrect
list_display controls the columns shown in the admin list view for a model.How do you add a custom column using a method in
list_display?✗ Incorrect
You add the method name as a string in
list_display inside the admin class.Which of these is NOT a valid
list_display entry?✗ Incorrect
Entries must be model fields, admin methods, or callables. Random strings cause errors.
How can you make a method column sortable in
list_display?✗ Incorrect
Setting
admin_order_field on the method links it to a model field for sorting.If a method in
list_display returns None, what will you see in the admin list?✗ Incorrect
Returning None results in an empty cell in the list view.
Explain how to customize the columns shown in Django admin list view using
list_display.Think about what you want to see in the table of records.
You got /4 concepts.
Describe how to make a custom method column sortable in Django admin list display.
Sorting needs a connection to a real model field.
You got /4 concepts.