Hi there,
I'm on DRF 3.1.0 and Django 1.7.6 and have serializers like below:
class AddressSerializer(serializers.ModelSerializer):
zip = serializers.RegexField(regex=r'^\d{5}(-\d{4})?$')
addr1 = serializers.Field()
class Meta:
model = Address
class CustomerSerializer(serializers.ModelSerializer):
ship_address = AddressSerializer(required=False)
email = serializers.Field()
class Meta:
model = Customer
and it works fine when doing like this (usual dict):
CustomerSerializer(data={'email':'test@test.test'}).is_valid() # Gives True, which is ok
BUT it fails when serializer created with request.data in the view, because request.data has MergeDict type
from rest_framework.requests import MergeDict
cs=CustomerSerializer(data=MergeDict({'email':'test@test.test'}))
cs.is_valid()# Gives False
cs.errors # {'ship_address': {'zip': [u'This field is required.'], 'addr1': [u'This field is required.']}}
I understand that 'zip' and 'addr1' required fields on Address, but in this case Address is not required at all.
Am I doing smth wrong or any ideas how to fix that ?
Thanks in advance
Hi there,
I'm on DRF 3.1.0 and Django 1.7.6 and have serializers like below:
and it works fine when doing like this (usual dict):
BUT it fails when serializer created with request.data in the view, because request.data has MergeDict type
I understand that 'zip' and 'addr1' required fields on Address, but in this case Address is not required at all.
Am I doing smth wrong or any ideas how to fix that ?
Thanks in advance