class Meta: model = Testsuits fields = ('id', 'name', 'project', 'project_id', 'include', 'create_time', 'update_time') read_only = ('create_time', 'update_time') extra_kwargs = { 'create_time': { 'format': datetime_fmt() }, 'update_time': { 'format': datetime_fmt() }, 'include': { 'validators': [validate_include] } }
class Meta: model = Testsuits fields = ('id', 'name', 'project', 'project_id', 'include', 'create_time', 'update_time') extra_kwargs = { 'create_time': { 'format': datetime_fmt() }, 'update_time': { 'format': datetime_fmt() }, 'include': { 'write_only': True, 'validators': [validate_include] # 自定义校验方法,传入的值非列表有提示 } }
class Meta: model = Envs exclude = ("update_time", ) extra_kwargs = { 'create_time': { 'read_only': True, 'format': common.datetime_fmt(), }, }
class Meta: model = Interfaces fields = ('id', 'name', 'tester', 'create_time', 'desc', 'project', 'project_id') extra_kwargs = { 'create_time': { 'read_only': True, 'format': common.datetime_fmt() } }
class Meta: model = Projects exclude = ('update_time', ) extra_kwargs = { 'create_time': { 'read_only': False, 'format': common.datetime_fmt(), }, }
class Meta: model = Interfaces # fields = ('id', 'name', 'leader', 'tester', 'programmer', 'create_time', 'update_time', 'email') # fields = '__all__' exclude = ("update_time", ) extra_kwargs = { 'create_time': { 'read_only': True, 'format': common.datetime_fmt(), }, }
class Meta: model = Reports exclude = ('update_time', ) extra_kwargs = { 'create_time': { 'format': datetime_fmt() }, 'html': { 'write_only': True } }
class Meta: model = Reports exclude = ('update_time', ) # 不需要输出 # 输出校验 extra_kwargs = { 'create_time': { 'format': common.datetime_fmt() # 创建时间输出格式为此函数 }, 'html': { 'write_only': True }, }
class Meta: # 类名固定 # 指定要生成的模型 model = Testsuits # fields类属性来指定,模型类中哪些字段需要输入或输出 fields = ('id', 'name', 'project', 'project_id', 'include', 'create_time', 'update_time') extra_kwargs = { 'create_time': { # 只需要输出 'read_only': True, 'format': datetime_fmt() }, 'update_time': { # 只需要输出 'read_only': True, 'format': datetime_fmt() }, 'include': { # 只需要输入 # 'write_only': True 'validators': [validate_include] }, }
class Meta: model = Interfaces fields = '__all__' extra_kwargs = { "tester": { 'label': '研发人员', 'write_only': True, 'max_length': 20, 'min_length': 2 }, "name": { 'max_length': 20, 'min_length': 2, 'validators': [is_name_contain_x] }, "create_time": { 'read_only': True, 'format': common.datetime_fmt(), }, "update_time": { 'read_only': True, 'format': common.datetime_fmt(), } }
class Meta: # 类名固定 # 需要在Meta内部类这两个指定model类属性:需要按照哪一个模型类创建 # 指定要生成的模型 model = Projects # 把需要排除的字段放在exclude中,过滤不生成的字段,不参与输入也不参与输出 exclude = ('update_time', ) extra_kwargs = { 'create_time': { # 只需要输出不需要输入 'read_only': True, 'format': common.datetime_fmt(), }, }
class Meta: model = Interfaces fields = ('id', 'name', 'tester', 'project', 'create_time', 'project_id', 'desc') extra_kwargs = { "create_time": { 'read_only': True, 'format': common.datetime_fmt() }, "name": { "validators": [ validators.UniqueValidator(queryset=model.objects.all(), message='项目名称不能重复') ] } }
class Meta: # 类名固定 # 需要在Meta内部类这两个指定model类属性:需要按照哪一个模型类创建 # 指定要生成的模型 model = Interfaces # fields类属性来指定,模型类中哪些字段需要输入或输出 # 指定当前模型类的字段 # 将模型类所有的字段都生成序列化器类中的字段 fields = ('id', 'name', 'tester', 'create_time', 'desc', 'project', 'project_id') extra_kwargs = { 'create_time': { 'read_only': True, 'format': common.datetime_fmt() } }