Python rest_framework.serializers.DictField() Examples

The following are 5 code examples for showing how to use rest_framework.serializers.DictField(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module rest_framework.serializers , or try the search function .

Example 1
Project: polemarch   Author: vstconsulting   File: serializers.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def _writable_fields(self) -> List:
        writable_fields = super(_SignalSerializer, self)._writable_fields
        fields = []
        attrs = [
            'field_name', 'source_attrs', 'source',
            'read_only', 'required', 'write_only', 'default'
        ]
        for field in writable_fields:
            if not isinstance(field, DataSerializer):
                fields.append(field)
                continue
            field_object = serializers.DictField()
            for attr in attrs:
                setattr(field_object, attr, getattr(field, attr, None))
            fields.append(field_object)
        return fields 
Example 2
def get_fields(self):
        query_facet_counts = self.instance.pop('queries', {})

        field_mapping = super(BaseHaystackFacetSerializer, self).get_fields()

        query_data = self.format_query_facet_data(query_facet_counts)

        field_mapping['queries'] = DictField(query_data, child=QueryFacetFieldSerializer(), required=False)

        if self.serialize_objects:
            field_mapping.move_to_end('objects')

        self.instance['queries'] = query_data

        return field_mapping 
Example 3
Project: drf_openapi   Author: limdauto   File: entities.py    License: MIT License 5 votes vote down vote up
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 4
Project: graphene-django   Author: graphql-python   File: test_field_converter.py    License: MIT License 5 votes vote down vote up
def test_should_dict_convert_dict():
    assert_conversion(serializers.DictField, DictType) 
Example 5
Project: django-rest-framework-mongoengine   Author: umutbozkurt   File: fields.py    License: MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        self.allow_empty = kwargs.pop('allow_empty', True)
        super(DictField, self).__init__(*args, **kwargs)