From 75143dcfb63582beed563db98f6ed39722517170 Mon Sep 17 00:00:00 2001 From: Brandon Birkholz Date: Wed, 29 Jun 2016 17:39:54 -0700 Subject: [PATCH] Convert includes from camel to snake case --- rest_framework_json_api/renderers.py | 2 ++ rest_framework_json_api/serializers.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/rest_framework_json_api/renderers.py b/rest_framework_json_api/renderers.py index 0a11063e..83332566 100644 --- a/rest_framework_json_api/renderers.py +++ b/rest_framework_json_api/renderers.py @@ -4,6 +4,7 @@ import copy from collections import OrderedDict +import inflection from django.utils import six, encoding from rest_framework import relations from rest_framework import renderers @@ -237,6 +238,7 @@ def extract_included(fields, resource, resource_instance, included_resources): context = current_serializer.context included_serializers = utils.get_included_serializers(current_serializer) included_resources = copy.copy(included_resources) + included_resources = [inflection.underscore(value) for value in included_resources] for field_name, field in six.iteritems(fields): # Skip URL field diff --git a/rest_framework_json_api/serializers.py b/rest_framework_json_api/serializers.py index 953c4437..24a73015 100644 --- a/rest_framework_json_api/serializers.py +++ b/rest_framework_json_api/serializers.py @@ -1,3 +1,4 @@ +import inflection from django.utils.translation import ugettext_lazy as _ from rest_framework.exceptions import ParseError from rest_framework.serializers import * @@ -75,7 +76,7 @@ def validate_path(serializer_class, field_path, path): serializers = get_included_serializers(serializer_class) if serializers is None: raise ParseError('This endpoint does not support the include parameter') - this_field_name = field_path[0] + this_field_name = inflection.underscore(field_path[0]) this_included_serializer = serializers.get(this_field_name) if this_included_serializer is None: raise ParseError(