Skip to content

Commit 575742b

Browse files
committed
Applied suggested changes
1 parent e3c66b0 commit 575742b

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

example/tests/test_views.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ def test_new_comment_data_patch_to_many_relationship(self):
240240
previous_response = {
241241
'data': [
242242
{'type': 'comments',
243-
'id': f'{self.second_comment.id}'
243+
'id': str(self.second_comment.id)
244244
}
245245
],
246-
'links': {'self': f'http://testserver/authors/{self.author.id}/relationships/comment_set'}
246+
'links': {'self': 'http://testserver/authors/{}/relationships/comment_set'.format(self.author.id)}
247247
}
248248

249249
response = self.client.get(url)
@@ -253,17 +253,17 @@ def test_new_comment_data_patch_to_many_relationship(self):
253253
new_patched_response = {
254254
'data': [
255255
{'type': 'comments',
256-
'id': f'{comment.id}'
256+
'id': str(comment.id)
257257
}
258258
],
259-
'links': {'self': f'http://testserver/authors/{self.author.id}/relationships/comment_set'}
259+
'links': {'self': 'http://testserver/authors/{}/relationships/comment_set'.format(self.author.id)}
260260
}
261261

262262
response = self.client.patch(url, data=request_data)
263263
assert response.status_code == 200
264264
assert response.json() == new_patched_response
265265

266-
assert Comment.objects.filter(id=self.second_comment.id).exists
266+
assert Comment.objects.filter(id=self.second_comment.id).exists()
267267

268268

269269
class TestRelatedMixin(APITestCase):

rest_framework_json_api/views.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def get(self, request, *args, **kwargs):
254254
def remove_relationships(self, instance_manager, field):
255255
field_object = getattr(instance_manager, field)
256256

257-
if getattr(field_object, "null"):
257+
if field_object.null:
258258
for obj in instance_manager.all():
259259
setattr(obj, field_object.name, None)
260260
obj.save()
@@ -273,16 +273,19 @@ def patch(self, request, *args, **kwargs):
273273
data=request.data, model_class=related_model_class, many=True
274274
)
275275
serializer.is_valid(raise_exception=True)
276-
# related_instance_or_manager.all().delete()
277276

278277
# for to one
279278
if hasattr(related_instance_or_manager, "field"):
280-
related_instance_or_manager = self.remove_relationships(instance_manager=related_instance_or_manager,
281-
field="field")
279+
related_instance_or_manager = self.remove_relationships(
280+
instance_manager=related_instance_or_manager,
281+
field="field"
282+
)
282283
# for to many
283284
else:
284-
related_instance_or_manager = self.remove_relationships(instance_manager=related_instance_or_manager,
285-
field="target_field")
285+
related_instance_or_manager = self.remove_relationships(
286+
instance_manager=related_instance_or_manager,
287+
field="target_field"
288+
)
286289

287290
# have to set bulk to False since data isn't saved yet
288291
class_name = related_instance_or_manager.__class__.__name__

0 commit comments

Comments
 (0)