學習django之構建Web是Meta嵌套類的幾處使用

來源:互聯網
上載者:User

標籤:style   使用   sp   for   on   資料   bs   ef   amp   

Django中meta嵌套類的使用

1、模型中使用嵌套類

   在定義抽象模型時如:

   class Meta :

       abstract=true

用來指明你建立的模型是一個抽象基礎類的模型繼承。

 

2、在一個對象對多個對象時,其定義的名字怎樣顯示

 

3、查詢資料時表示預設排序

 

4、定義資料表的名字

   如:class Meta:

            db_table=’Demo’

5、時間排序

   比如你定義的模型中有一個時期時間變數  timestamp=model.DateTimeField()

對時間戳記變數進行降序排列為:

   class Meta:

      ordering(‘-timestamp’,)

6、在ModelForm的Meta嵌套類允許定義field和exclude

   

如: from myproject.myapp.model import Person

     class PersonForm (forms.ModelForm):

         class Meta:

             model=Person   

             exclude=(‘middle’)或   

             field=(‘first’,’last’)

學習django之構建Web是Meta嵌套類的幾處使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.