<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] 修改列表頁樣式 ## 添加樣式 ### 1. 每頁數據條數 `list_per_page` 選項設置每頁數據的條數,默認每頁100條數據。 例:修改每頁顯示3條數據 ```python @admin.register(Book) class BookAdmin(admin.ModelAdmin): list_per_page = 3 ``` 顯示效果: ![](https://box.kancloud.cn/aa852e3fe7054be144e64cb34c1e8403_604x179.png) ### 2. 操作選項的位置 `actions_on_top` 設置操作選項是否在頂部顯示,默認為 `True` ``` actions_on_top = True ``` `actions_on_bottom` 設置操作選項是否在頂部顯示,默認為 `False` ``` actions_on_top = False ``` 例:修改操作選項到下邊 ```python @admin.register(Book) class BookAdmin(admin.ModelAdmin): ... actions_on_top = False actions_on_bottom = True ``` 顯示效果: ![](https://box.kancloud.cn/80dfa2ec9383bc5a0bd33ea840f68907_587x278.png) ### 3. 列表中的列顯示 `list_display` 選項設置顯示的列 格式如下 ``` list_display = [列1, 列2] ``` 例:顯示書籍的id,標題,發布日期 ```python @admin.register(Book) class BookAdmin(admin.ModelAdmin): list_display = ['id', 'b_title', 'b_pub_date'] ``` 顯示效果: ![](https://box.kancloud.cn/ceb48ed0cb5e9ed85ea13a785525dce2_1053x242.png) ### 4. 將方法作為列 列不僅可以是字段,也可以是方法,要求方法必須有返回值。 例:使用方法列在后臺顯示閱讀次數 1. 在 `Book` 模型類中添加代碼 ```python class Book(models.Model): ... def read(self): return '%s 次' % self.b_read read.short_description = "閱讀次數" read.admin_order_field = 'b_read' ``` - `short_description` 屬性設置該方法在admin站點中顯示的名字,類似字段的 `verbose_name` 屬性。 - `admin_order_field` 設置方法列可排序,格式如下 ``` 方法名.admin_order_field = '字段名' ``` 2. 添加顯示列 ```python @admin.register(Book) class BookAdmin(admin.ModelAdmin): list_display = ['id', 'b_title', 'b_pub_date', 'read'] ``` 顯示效果: ![](https://box.kancloud.cn/e4354ac5395cffa27ad454ab5106c06c_1446x164.png) ### 5 訪問關聯對象 可以使用方法獲得被關聯對象數據,并顯示。 例:在角色頁面顯示關聯圖書閱讀次數 1. 修改 `Role` 模型類 ```python def read(self): return '%s 次' % self.r_book.b_read read.short_description = "閱讀次數" ``` 2. 添加顯示列 ```python @admin.register(Role) class RoleAdmin(admin.ModelAdmin): list_display = ['id', 'r_name', 'r_book', 'read'] ``` 顯示效果: ![](https://box.kancloud.cn/13c36d401a9bd236eeebe29e43793336_1543x356.png) ### 6. 過濾器 `list_filter` 屬性用于在右側顯示過濾器,會把有重復值的數據過濾出來,方便快速選擇。 語法格式: ``` list_filter=[字段1, 字段2] ``` 例:使用書名和性別過濾角色 ```python @admin.register(Role) class RoleAdmin(admin.ModelAdmin): list_filter = ['r_book', 'r_gender'] ``` 顯示效果: ![](https://box.kancloud.cn/e547def4fbdcd460a332927b18e401b8_276x381.png) ### 7. 搜索框 顯示搜索框,用于對指定的字段進行搜索,支持模糊查詢。 語法如下: ``` search_fields=[] ``` 例:使用角色名字搜索 ```python @admin.register(Role) class RoleAdmin(admin.ModelAdmin): search_fields = ['r_name'] ``` ![](https://box.kancloud.cn/92f429173b910d3b16f1d0fd9f997932_1351x291.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看