简体   繁体   中英

ModelSerializer doesn't respect the required attribute on a field

If I have:

class Example(serializers.ModelSerializer):
    time = DateTimeRangeField(required=False)

it will fail with an error:

{'time': ['This field is required.']}

However if this was serializers.Serializer it respects the required attribute on the field. Has anybody else come across this? Any ideas on how to make a field not required?

DateTimeRangeField 不是 Django REST框架字段,因此就像您根本没有提供任何字段一样。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM