Python rest_framework.serializers.DictField() Examples

The following are 5 code examples of rest_framework.serializers.DictField(). 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 polemarch with 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
Source File: serializers.py    From course-discovery with GNU Affero General Public License v3.0 5 votes vote down vote up
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
Source File: entities.py    From drf_openapi with 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
Source File: test_field_converter.py    From graphene-django with MIT License 5 votes vote down vote up
def test_should_dict_convert_dict():
    assert_conversion(serializers.DictField, DictType) 
Example #5
Source File: fields.py    From django-rest-framework-mongoengine with 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)