英文: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',)