Django Rest Framework ModelSerialzer field doesn't respect required=False -
using django rest framework 3.1.1, have following serializer:
class commentserializer(contentserializer): created_by = userserializer(required=false) content = serializers.primarykeyrelatedfield(queryset=content.objects.all(), required=false) class meta: model = comment
while content
field respects required=false
parameter, created_by
not, in result, gives me list of "this field required" validation errors inside userserializer:
{"created_by":{"username":["this field required."],"user_permissions":["this field required."],"password":["this field required."],"groups":["this field required."],"profile_picture":["this field required."]}}
according documentation section "dealing nested objects" demonstrates usage serializer.
what have tried:
my previous question , tried adding
get_validation_exclusions
did not believe it's been attended in issue.changing created_by
created_by = serializers.primarykeyrelatedfield(required=false)
worked, not want.- a quick search in existing issue shows not 1 having problem: https://github.com/tomchristie/django-rest-framework/issues/2719
update:
i have created couple of test cases (see here) couldn't replicate issue, looks happening via ajax post.
i added read_only=true
created_by field, it's working fine.
class commentserializer(contentserializer): created_by = userserializer(required=false, read_only=true) content = serializers.primarykeyrelatedfield(queryset=content.objects.all(), required=false) class meta: model = comment
Comments
Post a Comment