Bootstrap

12.Django中ModelForm的使用

ModelForm的优点:

                ①对用户提交的数据进行基础校验,自己也可以二次定义校验,

                ②自动根据ModelForm文件里的widgets 生成HTML标签,

                ③页面上可以展示错误提示,

                ④不用对表单提交的每个数据都手动获取

1.Model(项目表数据模型定义)

class projectInfo(models.Model):
    projectName = models.CharField(max_length=50, null=True, blank=True, default=None)
    projectDescription = models.CharField(max_length=50, null=True, blank=True, default=None)
    projectHost = models.CharField(max_length=50, null=True, blank=True, default=None)
    status_choices = (
        (1, "研发中"),
        (2, "研发完毕"),
        (3, "测试中"),
        (4, "测试完毕"),
    )
    projectStatus = models.SmallIntegerField(verbose_name="状态", choices=status_choices)

    projectOwner = models.CharField(max_length=50, null=Tr
;