今天看了一下Django的Model API 文檔
英文:http://www.djangoproject.com/documentation/model_api/#db-column
中文:http://www.woodpecker.org.cn/obp/django/django-faq/model-api.html
實例文件:/Files/maplye/django/Study.rar
我的model如下:
英文:http://www.djangoproject.com/documentation/model_api/#db-column
中文:http://www.woodpecker.org.cn/obp/django/django-faq/model-api.html
實例文件:/Files/maplye/django/Study.rar
我的model如下:
from django.db import models
# Test Model Fields
# Test FilePathField
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
class TestModel(models.Model):
name = models.CharField('名稱',maxlength=100, unique=True)
content = models.TextField('備註',blank=True)
#顯示某文件夾下文件列表
#path 路徑
#match 過濾文件的正則表達式
#recursive 是否顯示子目錄,默認爲False
filepath = models.FilePathField('文件列表',path="./files/",match=".+\.jpg",recursive=True,blank=True)
#upload_to保存文件的地址,相對於MEDIA_ROOT的路徑
upload = models.FileField('上傳文件',upload_to="files/%Y/%m/%d",blank=True)
#max_digits爲總位數
#decimal_places爲小數點後面位數
floats = models.FloatField('金額', max_digits=5, decimal_places=2,default=0,blank=True)
photo= models.ImageField("上傳圖片",default='None.jpg',upload_to='photos/%Y/%m/%d',height_field='240',width_field='320',core=True, blank=True)
integers = models.IntegerField('數字',default=0, blank=True)
ips = models.IPAddressField('地址',blank=True)
slugs = models.SlugField(prepopulate_from=("ips", "name"))
testdate = models.DateField('測試日期', blank=True)
testtime = models.TimeField('測試時間', blank=True)
testdatetime = models.DateTimeField('測試日期時間', blank=True)
gender = models.CharField(maxlength=1, choices=GENDER_CHOICES,help_text="性別",radio_admin=True)
def __str__(self):
return self.name
class Admin:
list_display = ('name',)
在admin中查看的結果如下:# Test Model Fields
# Test FilePathField
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
class TestModel(models.Model):
name = models.CharField('名稱',maxlength=100, unique=True)
content = models.TextField('備註',blank=True)
#顯示某文件夾下文件列表
#path 路徑
#match 過濾文件的正則表達式
#recursive 是否顯示子目錄,默認爲False
filepath = models.FilePathField('文件列表',path="./files/",match=".+\.jpg",recursive=True,blank=True)
#upload_to保存文件的地址,相對於MEDIA_ROOT的路徑
upload = models.FileField('上傳文件',upload_to="files/%Y/%m/%d",blank=True)
#max_digits爲總位數
#decimal_places爲小數點後面位數
floats = models.FloatField('金額', max_digits=5, decimal_places=2,default=0,blank=True)
photo= models.ImageField("上傳圖片",default='None.jpg',upload_to='photos/%Y/%m/%d',height_field='240',width_field='320',core=True, blank=True)
integers = models.IntegerField('數字',default=0, blank=True)
ips = models.IPAddressField('地址',blank=True)
slugs = models.SlugField(prepopulate_from=("ips", "name"))
testdate = models.DateField('測試日期', blank=True)
testtime = models.TimeField('測試時間', blank=True)
testdatetime = models.DateTimeField('測試日期時間', blank=True)
gender = models.CharField(maxlength=1, choices=GENDER_CHOICES,help_text="性別",radio_admin=True)
def __str__(self):
return self.name
class Admin:
list_display = ('name',)