Repository: django-json-api/django-rest-framework-json-api

Issue:
Demo site 500 
Following links on demo site return Server Error 500:
[http://json-api.jerel.co/](http://json-api.jerel.co/)

```
       "blogs": "http://json-api.jerel.co/blogs",
       "entries": "http://json-api.jerel.co/entries",

```

Note other links work:
```
        "authors": "http://json-api.jerel.co/authors",
        "comments": "http://json-api.jerel.co/comments"

```
Cheers.


Discussion:
Thanks, @elena. I believe this runs on the personal website of @jerel. If I had to venture a guess, the site is probably missing some database migrations that were recently added the demo project.
It's running on a private server. I'll try to take a look, probably an
issue with the reset script or migrations
So, it's throwing `ImportError: No module named polymorphic`. Merely installing `django-polymorphic` doesn't fix it. Evidently there's a package missing from the requirements file. But does, or should, the demo even use polymorphism out of the box?
@jerel, I believe that the polymorphic branch that was merged *did* update the demo project to use polymorphic models in some locations. I'm surprised (saddened?) that installing `django-polymorphic` doesn't solve the problem.

Do you have any details on what it is reporting after you install `django-polymorphic`? Did you get past the `ImportError`?
So, I've worked with this a bit and found the demo hadn't applied migrations correctly. The `/blogs` endpoint is working fine but `/entries` is throwing `Could not resolve URL for hyperlinked relationship using view name "entry-relationships".`

I'm out of time for the moment but hopefully that gets somebody else pointed in the right direction. You can replicate by checking out the `develop` branch and running `django-admin.py runserver --settings=example.settings`
@leo-naeka or @astronouth7303, something is wrong with the demo site and I'm guessing it's related to the polymorphic changes. Could one of you take a quick look and see if you could figure out the problem? I'd hope to see the demo site working again before a release goes out.
I have found a few bugs:

1. The example now requires `packaging` (`example/serializers.py`). I'm guessing this is the actual cause of the bug.
2. `/entries` produces `ImproperlyConfigured at /entries`: `Could not resolve URL for hyperlinked relationship using view name "entry-relationships".`
3. `/projects` produces `AttributeError at /projects`: `'list' object has no attribute '_meta'`

Resolving patch:
diff --git a/rest_framework_json_api/serializers.py b/rest_framework_json_api/serializers.py
--- a/rest_framework_json_api/serializers.py
+++ b/rest_framework_json_api/serializers.py
@@ -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()


Test patch:
diff --git a/example/tests/integration/test_polymorphism.py b/example/tests/integration/test_polymorphism.py
--- a/example/tests/integration/test_polymorphism.py
+++ b/example/tests/integration/test_polymorphism.py
@@ -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))