File tree 3 files changed +19
-10
lines changed
3 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -248,6 +248,19 @@ When set to pluralize:
248
248
Both ` JSON_API_PLURALIZE_RELATION_TYPE ` and ` JSON_API_FORMAT_RELATION_KEYS ` can be combined to
249
249
achieve different results.
250
250
251
+ ### Working with polymorphic resources
252
+
253
+ This package can defer the resolution of the type of polymorphic models instances to get the appropriate type.
254
+ However, most models are not polymorphic and for performance reasons this is only done if the underlying model is a subclass of a polymorphic model.
255
+
256
+ Polymorphic ancestors must be defined on settings like this:
257
+
258
+ ``` python
259
+ JSON_API_POLYMORPHIC_ANCESTORS = (
260
+ ' polymorphic.models.PolymorphicModel' ,
261
+ )
262
+ ```
263
+
251
264
### Meta
252
265
253
266
You may add metadata to the rendered json in two different ways: ` meta_fields ` and ` get_root_meta ` .
Original file line number Diff line number Diff line change 15
15
REST_FRAMEWORK .update ({
16
16
'PAGE_SIZE' : 1 ,
17
17
})
18
+ JSON_API_POLYMORPHIC_ANCESTORS = (
19
+ 'polymorphic.models.PolymorphicModel' ,
20
+ )
Original file line number Diff line number Diff line change 22
22
HyperlinkedRouterField = type (None )
23
23
24
24
POLYMORPHIC_ANCESTORS = ()
25
- try :
26
- from polymorphic .models import PolymorphicModel
27
- POLYMORPHIC_ANCESTORS += (PolymorphicModel ,)
28
- except ImportError :
29
- pass
30
- try :
31
- from typedmodels .models import TypedModel
32
- POLYMORPHIC_ANCESTORS += (TypedModel ,)
33
- except ImportError :
34
- pass
25
+ for ancestor in getattr (settings , 'JSON_API_POLYMORPHIC_ANCESTORS' , ()):
26
+ ancestor_class = import_class_from_dotted_path (ancestor )
27
+ POLYMORPHIC_ANCESTORS += (ancestor_class ,)
35
28
36
29
37
30
def get_resource_name (context ):
You can’t perform that action at this time.
0 commit comments