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 c77fe0f

Browse files
n2ygksliverc
authored andcommitted
Allow OPTIONS request to be used on RelationshipView (#633)
1 parent 22476fe commit c77fe0f

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ any parts of the framework not mentioned in the documentation should generally b
1515
* Avoid exception when trying to include skipped relationship
1616
* Don't swallow `filter[]` params when there are several
1717
* Fix DeprecationWarning regarding collections.abc import in Python 3.7
18+
* Allow OPTIONS request to be used on RelationshipView.
1819

1920
## [2.7.0] - 2019年01月14日
2021

‎example/tests/test_views.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,39 @@ def test_new_comment_data_patch_to_many_relationship(self):
274274

275275
assert Comment.objects.filter(id=self.second_comment.id).exists()
276276

277+
def test_options_entry_relationship_blog(self):
278+
url = reverse(
279+
'entry-relationships', kwargs={'pk': self.first_entry.id, 'related_field': 'blog'}
280+
)
281+
response = self.client.options(url)
282+
expected_data = {
283+
"data": {
284+
"name": "Entry Relationship",
285+
"description": "",
286+
"renders": [
287+
"application/vnd.api+json",
288+
"text/html"
289+
],
290+
"parses": [
291+
"application/vnd.api+json",
292+
"application/x-www-form-urlencoded",
293+
"multipart/form-data"
294+
],
295+
"allowed_methods": [
296+
"GET",
297+
"POST",
298+
"PATCH",
299+
"DELETE",
300+
"HEAD",
301+
"OPTIONS"
302+
],
303+
"actions": {
304+
"POST": {}
305+
}
306+
}
307+
}
308+
assert response.json() == expected_data
309+
277310

278311
class TestRelatedMixin(APITestCase):
279312

‎rest_framework_json_api/serializers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ class ResourceIdentifierObjectSerializer(BaseSerializer):
2929

3030
def __init__(self, *args, **kwargs):
3131
self.model_class = kwargs.pop('model_class', self.model_class)
32-
if 'instance' not in kwargs and not self.model_class:
33-
raise RuntimeError(
34-
'ResourceIdentifierObjectsSerializer must be initialized with a model class.'
35-
)
32+
# this has no fields but assumptions are made elsewhere that self.fields exists.
33+
self.fields = {}
3634
super(ResourceIdentifierObjectSerializer, self).__init__(*args, **kwargs)
3735

3836
def to_representation(self, instance):

0 commit comments

Comments
(0)

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