0
0
Djangoframework~5 mins

List display configuration in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AWhich fields are editable in the form
BWhich fields show as columns in the list view
CWhich models are registered
DWhich users can access admin
How do you add a custom column using a method in list_display?
AAdd the method name as a string in <code>list_display</code>
BAdd the method as a decorator
COverride the model's <code>__str__</code> method
DAdd the method to the model's Meta class
Which of these is NOT a valid list_display entry?
AA model field name
BA method name in the admin class
CA random string not matching any field or method
DA callable returning a value
How can you make a method column sortable in list_display?
AUse <code>list_filter</code> instead
BMake the method static
CReturn a number from the method
DSet <code>admin_order_field</code> on the method
If a method in list_display returns None, what will you see in the admin list?
AAn empty column cell
BAn error message
CThe method name displayed
DThe default field value
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.