Python rest_framework.serializers.StringRelatedField() Examples

The following are 1 code examples for showing how to use rest_framework.serializers.StringRelatedField(). 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: wagtailmodelchoosers   Author: springload   File:    License: MIT License 6 votes vote down vote up
def build_serializer(self, cls, model_name):
        Dynamically build a model serializer class
        class_name = "%sSerializer" % model_name
        meta_class = type('Meta', (), {'model': cls, 'fields': '__all__'})
        serializer_args = {'Meta': meta_class}

        if hasattr(cls, 'content_type'):
                'content_type': serializers.StringRelatedField()

        model_serializer = type(class_name, (serializers.ModelSerializer,), serializer_args)

        return model_serializer