Python rest_framework.serializers.JSONField() Examples
The following are 3
code examples of rest_framework.serializers.JSONField().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rest_framework.serializers
, or try the search function
.
Example #1
Source File: serializers.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def validate(self, data): data = super().validate(data) errors = {} for name, field in self.fields.items(): if type(field) is serializers.CharField: value = data.get(name) if value: value = value.strip() data[name] = value valid = sanitize_string(value) elif type(field) is serializers.JSONField: value = data.get(name, {}) or {} valid = all(sanitize_string(value[k]) for k in value) if not valid: errors[name] = [SANITIZE_ERROR] if errors: raise serializers.ValidationError(errors) return data
Example #2
Source File: entities.py From drf_openapi with MIT License | 5 votes |
def fallback_schema_from_field(self, field): """ Fallback schema for field that isn't inspected properly by DRF and probably won't land in upstream canon due to its hacky nature only for doc purposes """ title = force_text(field.label) if field.label else '' description = force_text(field.help_text) if field.help_text else '' # since we can't really inspect dictfield and jsonfield, at least display object as type # instead of string if isinstance(field, (serializers.DictField, serializers.JSONField)): return coreschema.Object( properties={}, title=title, description=description )
Example #3
Source File: test_field_converter.py From graphene-django with MIT License | 5 votes |
def test_should_json_convert_jsonstring(): assert_conversion(serializers.JSONField, graphene.types.json.JSONString)