![]() ![]() ![]() source = '*' : return ( False, None ) return ( True, None ) return ( False, data )īased on Django Classy Class-Based Views. This is because `source='*'` means # the field is passed the entire object, which is not null. fail ( 'null' ) # Nullable `source='*'` fields should not be skipped when its named # field is given a null value. get_default ()) if data is None : if not self. fail ( 'required' ) return ( True, self. root, 'partial', False ): raise SkipField () if self. get_default ()) if data is empty : if getattr ( self. Since serializer tries to access fields for model, you can describe properties by setting property in your model or define custom SerializerMethodField, all this could possibly use all fields of your model. ![]() * Return (False, data), indicating a non-empty value, that should have validation applied as normal. No you cannot achieve that by using builtin features of django and restframework. * Return (True, data), indicating an empty value that should be returned without any further validation being applied. * Raise `SkipField`, indicating that the field should be ignored. source_attrs, validated_value ) if errors : raise ValidationError ( errors ) return retĭef validate_empty_values ( self, data ): """ Validate empty values, and either: * Raise `ValidationError`, indicating invalid data. detail except DjangoValidationError as exc : errors = get_error_detail ( exc ) except SkipField : pass else : set_value ( ret, field. Python () Examples serializers.py drf-haystack MIT License getfields self compat.py django-rest. run_validation ( primitive_value ) if validate_method is not None : validated_value = validate_method ( validated_value ) except ValidationError as exc : errors = exc. get_value ( data ) try : validated_value = field. field_name, None ) primitive_value = field. _writable_fields for field in fields : validate_method = getattr ( self, 'validate_' + field. Default_error_messages =, code = 'invalid' ) ret = OrderedDict () errors = OrderedDict () fields = self. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |