Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c943167

Browse files
committed
Applied suggested changes
1 parent 3ced8cd commit c943167

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

‎example/tests/test_views.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from . import TestBase
1313
from .. import views
14-
from example.factories import AuthorFactory, EntryFactory, CommentFactory
14+
from example.factories import AuthorFactory, CommentFactory, EntryFactory
1515
from example.models import Author, Blog, Comment, Entry
1616
from example.serializers import AuthorBioSerializer, AuthorTypeSerializer, EntrySerializer
1717
from example.views import AuthorViewSet
@@ -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‎

Lines changed: 9 additions & 6 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /