我用的是Django 3.0.2
。
我定义了一个序列化器:
class ValueNestedSerializer(request_serializer.Serializer):
lower = request_serializer.DateTimeField(required=True, allow_null=False, format=None, input_formats=['%Y-%m-%dT%H:%M:%SZ',])
upper = request_serializer.DateTimeField(required=True, allow_null=False, format=None, input_formats=['%Y-%m-%dT%H:%M:%SZ',])
class DateRangeSerializer(request_serializer.Serializer):
attribute = request_serializer.CharField(default="UPLOAD_TIME")
operator = request_serializer.CharField(default="between_dates")
value = ValueNestedSerializer(required=True)
timezone = request_serializer.CharField(default="UTC")
timezoneOffset = request_serializer.IntegerField(default=0)
class BaseQueryPayload(request_serializer.Serializer):
appid = request_serializer.CharField(required=True, validators=[is_valid_appid])
filters = request_serializer.ListField(
required=True, validators=[is_validate_filters],
min_length=1
)
date_range = DateRangeSerializer(required=True)
有效载荷:
{
"appid": "6017cef554df4124274ef36d",
"filters": [
{
"table": "session",
"label": "1month"
}
],
"date_range": {
"value": {
"lower": "2023-01-01T01:00:98Z",
"upper": "2023-01-20T01:00:98Z"
}
},
"page": 1
}
但是我得到了这个验证错误:
{
"error": {
"date_range": {
"value": {
"lower": [
"Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm:ssZ."
],
"upper": [
"Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm:ssZ."
]
}
}
}
}
建议的格式YYYY-MM-DDThh:mm:ssZ
类似于传递的格式。
我错过什么了吗?
1条答案
按热度按时间7cwmlq891#
格式错误,因为秒必须在0-59范围内(当您尝试发布98秒时)