def to_internal_value(self, data): internal_value = ModelSerializer.to_internal_value(self, data) field = internal_value['field'] field_type = field.field_type typified_value_model = field_type.get_typified_value_model() typified_value_serializer_class = ( TYPIFIED_VALUE_SERIALIZERS_CLASS_DICT.get(typified_value_model)) if not typified_value_serializer_class: raise APIException( 'Serializer for {typified_value_model} is not defined'.format( typified_value_model=typified_value_model)) raw_value = data.get('value', None) if not raw_value and not field.required: return internal_value typified_value_serializer = typified_value_serializer_class(data=data) typified_value_serializer.fields['field'].queryset = ( self.fields['field'].get_queryset()) typified_value_serializer.fields['typified_value'].required = False regex_pattern = field_type.regex_pattern if regex_pattern: regex_validator = RegexValidator(regex=regex_pattern, ) typified_value_field = ( typified_value_serializer.fields['typified_value']) typified_value_field.validators.append(regex_validator) typified_value_serializer.is_valid(raise_exception=True) return typified_value_serializer.validated_data
def to_internal_value(self, data): internal_value = ModelSerializer.to_internal_value(self, data) field = internal_value['field'] field_type = field.field_type typified_value_model = field_type.get_typified_value_model() typified_value_serializer_class = ( TYPIFIED_VALUE_SERIALIZERS_CLASS_DICT.get(typified_value_model) ) if not typified_value_serializer_class: raise APIException( 'Serializer for {typified_value_model} is not defined'.format( typified_value_model=typified_value_model ) ) raw_value = data.get('value', None) if not raw_value and not field.required: return internal_value typified_value_serializer = typified_value_serializer_class(data=data) typified_value_serializer.fields['field'].queryset = ( self.fields['field'].get_queryset() ) typified_value_serializer.fields['typified_value'].required = False regex_pattern = field_type.regex_pattern if regex_pattern: regex_validator = RegexValidator( regex=regex_pattern, ) typified_value_field = ( typified_value_serializer.fields['typified_value'] ) typified_value_field.validators.append(regex_validator) typified_value_serializer.is_valid(raise_exception=True) return typified_value_serializer.validated_data
def to_internal_value(self, data): value_serializer = self.fields['values'].child field = value_serializer.fields['field'] field.queryset = Field.objects.filter( application_type__key=data.get('application_type'), ) return ModelSerializer.to_internal_value(self, data)