django framework for learning: twenty-one .admin list optimization and sorting

Foreword

Today, we learn about optimization and ranking list

ModelAdmin

django options.py inside the class definition ModelAdmin parameters can be set back admin page list, the relevant parameters are as follows

 

 

 Sort Field

Background list page, if you want to sort by a field, you can add a parameter ordering

 

 

 After refreshing the page, that is, in descending order of

List Page

List default setting of 100 records, we can also modify the next set to the default display per page 10, set list_per_page = 5

 

 

 refresh page

 

 

 

Set the default editable field

Some fields if you want to be able to directly edit the page in the list, you can add a list_editable parameters, so no need to enter a sub-page, you can edit the list of fields on the page directly
if there are multiple parameters, separated by commas inside the line, such as list_editable = ( ' name ',' age ',)

 

Refresh the page

 

 

 

 

 Note: title is the default link link field, this can not be added to list_editable inside, otherwise it will error

link link

List default point first field enter the edit page, if we want to add other fields can also click into the edit page, set list_display_links = ( 'title', 'body', 'author')

 

 

 Refresh the page title, page content and click-to-edit the page.

 

 

 

filter

If you want to quickly and easily find the corresponding author of the text, you can add a filter to display the list to the right page, such as setting list_filter = ( 'author', 'title')

 

 

 Refresh admin admin page

 

 

 Display is as follows, on the right side of the point, content name, to quickly find relevant content

Stratified by time

date_hierarchy default parameters to None, set a time field, can be selected from the puncturing time stratified

 

 

 Filter the table based on time

 

Guess you like

Origin www.cnblogs.com/liushui0306/p/12660032.html