django models建立表單的經常使用數據類型

字段:git

1、models.AutoField  自增列= int(11)正則表達式

  若是沒有的話,默認會生成一個名稱爲 id 的列,若是要顯示的自定義一個自增列,必須將給列設置爲主鍵 primary_key=True數據庫

2、models.CharField  字符串字段django

  必須 max_length 參數spa

3、models.BooleanField  布爾類型=tinyint(1)code

  不能爲空,Blank=True繼承

4、models.ComaSeparatedIntegerField  用逗號分割的數字=varchar索引

  繼承CharField,因此必須 max_lenght 參數圖片

5、models.DateField  日期類型 dateip

  對於參數,auto_now =True則每次更新都會更新這個時間;auto_now_add 則只是第一次建立添加,以後的更新再也不改變。

6、models.DateTimeField  日期類型 datetime

  同DateField的參數

7、models.Decimal  十進制小數類型= decimal

  必須指定整數位max_digits和小數位decimal_places

8、models.EmailField  字符串類型(正則表達式郵箱)=varchar

  對字符串進行正則表達式

9、models.FloatField  浮點類型= double

10、models.IntegerField  整形

11、models.BigIntegerField  長整形

  integer_field_ranges ={

    'SmallIntegerField':(-32768,32767),

    'IntegerField':(-2147483648,2147483647),

    'BigIntegerField':(-9223372036854775808,9223372036854775807),

    'PositiveSmallIntegerField':(0,32767),

    'PositiveIntegerField':(0,2147483647),

  }

12、models.IPAddressField  字符串類型(ip4正則表達式)

13、models.GenericIPAddressField  字符串類型(ip4和ip6是可選的)

  參數protocol能夠是:both、ipv四、ipv6

  驗證時,會根據設置報錯

14、models.NullBooleanField  容許爲空的布爾類型

15、models.PositiveIntegerFiel  正Integer

16、models.PositiveSmallIntegerField  正smallInteger

17、models.SlugField  減號、下劃線、字母、數字

18、models.SmallIntegerField  數字

  數據庫中的字段有:tinyint、smallint、int、bigint

19、models.TextField  字符串=longtext

20、models.TimeField  時間 HH:MM[:ss[.uuuuuu]]

21、models.URLField  字符串,地址正則表達式

22、models.BinaryField  二進制

23、models.ImageField圖片

24、models.FilePathField文件

 

參數:

1、null=True

  數據庫中字段是否能夠爲空

2、blank=True

  django的Admin中添加數據時是否可容許空值

3、primary_key =False

  主鍵,對AutoField設置主鍵後,就會代替原來的自增 id 

4、auto_now 和 auto_now_add

  auto_now 自動建立---不管添加或修改,都是當前操做的時間

  auto_now_add 自動建立---永遠是建立時的時間

5、choices

GENDER_CHOICE =(

(u'M', u'Male'),

(u'F', u'Female'),

)

gender = models.CharField(max_length=2,choices = GENDER_CHOICE)

6、max_length

7、default  默認值

8、verbose_name  Admin中字段的顯示名稱

9、name|db_column  數據庫中的字段名稱

10、unique=True  不容許重複

11、db_index =True  數據庫索引

12、editable=True  在Admin裏是否可編輯

13、error_messages=None  錯誤提示

14、auto_created=False  自動建立

15、help_text  在Admin中提示幫助信息

16、validators=[]

17、upload-to

相關文章
相關標籤/搜索