From d3d31148586bd3c5c6ce6fb2be8e831fa782310c Mon Sep 17 00:00:00 2001 From: Leifur Halldor Asgeirsson Date: Mon, 5 Oct 2015 16:32:44 -0400 Subject: [PATCH] Small change to ResourceIdentifierObjectSerializer Allows `model_class` to be optionally defined as a class attribute. When defined as a class attribute, `model class` may still be overwritten on instantiation via kwarg. --- rest_framework_json_api/serializers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rest_framework_json_api/serializers.py b/rest_framework_json_api/serializers.py index 546b9e57..5cb78363 100644 --- a/rest_framework_json_api/serializers.py +++ b/rest_framework_json_api/serializers.py @@ -13,8 +13,10 @@ class ResourceIdentifierObjectSerializer(BaseSerializer): 'incorrect_type': _('Incorrect type. Expected pk value, received {data_type}.'), } + model_class = None + def __init__(self, *args, **kwargs): - self.model_class = kwargs.pop('model_class', None) + self.model_class = kwargs.pop('model_class', self.model_class) if 'instance' not in kwargs and not self.model_class: raise RuntimeError('ResourceIdentifierObjectsSerializer must be initialized with a model class.') super(ResourceIdentifierObjectSerializer, self).__init__(*args, **kwargs)