Skip to content

Commit fb6196a

Browse files
committed
DRY Fix for relation_type
1 parent ad4caaf commit fb6196a

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

rest_framework_json_api/utils.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,11 @@ def extract_relationships(fields, resource, resource_instance):
198198
if not isinstance(field, (RelatedField, ManyRelatedField, BaseSerializer)):
199199
continue
200200

201+
relation_type = get_related_resource_type(field)
202+
201203
if isinstance(field, HyperlinkedIdentityField):
202204
# special case for HyperlinkedIdentityField
203205
relation_data = list()
204-
relation_type = get_related_resource_type(field)
205206
relation_manager = getattr(resource_instance, field_name)
206207
# Don't try to query an empty relation
207208
related = relation_manager.all() if relation_manager is not None else list()
@@ -219,7 +220,6 @@ def extract_relationships(fields, resource, resource_instance):
219220
continue
220221

221222
if isinstance(field, (PrimaryKeyRelatedField, HyperlinkedRelatedField)):
222-
relation_type = get_related_resource_type(field)
223223
relation_id = getattr(resource_instance, field_name).pk if resource.get(field_name) else None
224224

225225
relation_data = {
@@ -256,7 +256,6 @@ def extract_relationships(fields, resource, resource_instance):
256256

257257
if isinstance(field, ListSerializer):
258258
relation_data = list()
259-
260259
serializer = field.child
261260
relation_model = serializer.Meta.model
262261
relation_type = inflection.pluralize(relation_model.__name__).lower()

0 commit comments

Comments
 (0)