Skip to content

[WIP] Fix example app #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 11, 2017
Merged
Changes from all 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
4 changes: 3 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -69,7 +69,9 @@ From Source
## Running the example app

git clone https://github.com/django-json-api/django-rest-framework-json-api.git
cd django-rest-framework-json-api && pip install -e .
cd django-rest-framework-json-api
pip install -e .
pip install -r example/requirements.txt
django-admin.py runserver

Browse to http://localhost:8000
2 changes: 2 additions & 0 deletions example/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Requirements specifically for the example app
packaging
24 changes: 24 additions & 0 deletions example/tests/integration/test_polymorphism.py
Original file line number Diff line number Diff line change
@@ -78,6 +78,30 @@ def test_polymorphism_on_polymorphic_model_list_post(client):
assert content['data']['attributes']['artist'] == test_artist


def test_polymorphic_model_without_any_instance(client):
expected = {
"links": {
"first": "http://testserver/projects?page=1",
"last": "http://testserver/projects?page=1",
"next": None,
"prev": None
},
"data": [],
"meta": {
"pagination": {
"page": 1,
"pages": 1,
"count": 0
}
}
}

response = client.get(reverse('project-list'))
assert response.status_code == 200
content = load_json(response.content)
assert expected == content


def test_invalid_type_on_polymorphic_model(client):
test_topic = 'New test topic {}'.format(random.randint(0, 999999))
test_artist = 'test-{}'.format(random.randint(0, 999999))
2 changes: 1 addition & 1 deletion rest_framework_json_api/serializers.py
Original file line number Diff line number Diff line change
@@ -220,7 +220,7 @@ def get_fields(self):
"""
Return an exhaustive list of the polymorphic serializer fields.
"""
if self.instance is not None:
if self.instance not in (None, []):
if not isinstance(self.instance, QuerySet):
serializer_class = self.get_polymorphic_serializer_for_instance(self.instance)
return serializer_class(self.instance, context=self.context).get_fields()