【发布时间】:2018-12-06 01:11:43
【问题描述】:
如果我有:
class Example(serializers.ModelSerializer):
time = DateTimeRangeField(required=False)
它将失败并出现错误:
{'time': ['This field is required.']}
但是,如果这是 serializers.Serializer 它尊重字段上的必需属性。有没有其他人遇到过这个? 关于如何使字段不需要的任何想法?
【问题讨论】:
-
我认为您需要为模型中的时间字段设置
blank = True。 -
stackoverflow.com/questions/19780731/… 阅读答案 1 和 2。
-
展示你的模型,序列化器就像一个表单,它只是验证请求数据,模型中的时间字段必须传递
blank=True和null=True -
@Satendra,我试过了,它给出了同样的信息
标签: python django django-rest-framework django-serializer