Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ any parts of the framework not mentioned in the documentation should generally b
* Avoid exception when trying to include skipped relationship
* Don't swallow `filter[]` params when there are several
* Fix DeprecationWarning regarding collections.abc import in Python 3.7
* Allow OPTIONS request to be used on RelationshipView.

## [2.7.0] - 2019-01-14

Expand Down
33 changes: 33 additions & 0 deletions example/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,39 @@ def test_new_comment_data_patch_to_many_relationship(self):

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

def test_options_entry_relationship_blog(self):
url = reverse(
'entry-relationships', kwargs={'pk': self.first_entry.id, 'related_field': 'blog'}
)
response = self.client.options(url)
expected_data = {
"data": {
"name": "Entry Relationship",
"description": "",
"renders": [
"application/vnd.api+json",
"text/html"
],
"parses": [
"application/vnd.api+json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"allowed_methods": [
"GET",
"POST",
"PATCH",
"DELETE",
"HEAD",
"OPTIONS"
],
"actions": {
"POST": {}
}
}
}
assert response.json() == expected_data


class TestRelatedMixin(APITestCase):

Expand Down
6 changes: 2 additions & 4 deletions rest_framework_json_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ class ResourceIdentifierObjectSerializer(BaseSerializer):

def __init__(self, *args, **kwargs):
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.'
)
# this has no fields but assumptions are made elsewhere that self.fields exists.
self.fields = {}
super(ResourceIdentifierObjectSerializer, self).__init__(*args, **kwargs)

def to_representation(self, instance):
Expand Down