File tree Expand file tree Collapse file tree 4 files changed +30
-2
lines changed Expand file tree Collapse file tree 4 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,9 @@ From Source
6969## Running the example app
7070
7171 git clone https://github.com/django-json-api/django-rest-framework-json-api.git
72- cd django-rest-framework-json-api && pip install -e .
72+ cd django-rest-framework-json-api
73+ pip install -e .
74+ pip install -r example/requirements.txt
7375 django-admin.py runserver
7476
7577Browse to http://localhost:8000
Original file line number Diff line number Diff line change 1+ # Requirements specifically for the example app
2+ packaging
Original file line number Diff line number Diff line change @@ -78,6 +78,30 @@ def test_polymorphism_on_polymorphic_model_list_post(client):
7878 assert content ['data' ]['attributes' ]['artist' ] == test_artist
7979
8080
81+ def test_polymorphic_model_without_any_instance (client ):
82+ expected = {
83+ "links" : {
84+ "first" : "http://testserver/projects?page=1" ,
85+ "last" : "http://testserver/projects?page=1" ,
86+ "next" : None ,
87+ "prev" : None
88+ },
89+ "data" : [],
90+ "meta" : {
91+ "pagination" : {
92+ "page" : 1 ,
93+ "pages" : 1 ,
94+ "count" : 0
95+ }
96+ }
97+ }
98+
99+ response = client .get (reverse ('project-list' ))
100+ assert response .status_code == 200
101+ content = load_json (response .content )
102+ assert expected == content
103+
104+
81105def test_invalid_type_on_polymorphic_model (client ):
82106 test_topic = 'New test topic {}' .format (random .randint (0 , 999999 ))
83107 test_artist = 'test-{}' .format (random .randint (0 , 999999 ))
Original file line number Diff line number Diff line change @@ -219,7 +219,7 @@ def get_fields(self):
219219 """
220220 Return an exhaustive list of the polymorphic serializer fields.
221221 """
222- if self .instance is not None :
222+ if self .instance not in ( None , []) :
223223 if not isinstance (self .instance , QuerySet ):
224224 serializer_class = self .get_polymorphic_serializer_for_instance (self .instance )
225225 return serializer_class (self .instance , context = self .context ).get_fields ()
You can’t perform that action at this time.
0 commit comments