Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Down
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
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion rest_framework_json_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down