def create(self, validated_data): address = validated_data.pop('address') user = Customuser(**validated_data) user.save() serializer = AddressSerializer(data=address) if serializer.is_valid(raise_exception=True): serializer.save(customuser=user) return user
def test_serializer_create(): address = { "street": "test test", "number": 10, "zip_code": "00000000", "city": "SP", "state": "SP" } serializer = AddressSerializer(data=address) serializer.is_valid(raise_exception=True) serializer.save()
def _get_or_create_address(self, validated_data): address = validated_data.pop('address') address_serializer = AddressSerializer(data=address) address_serializer.is_valid(raise_exception=True) return address_serializer.save()