File tree Expand file tree Collapse file tree 3 files changed +19
-10
lines changed Expand file tree Collapse file tree 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:
248248Both ` JSON_API_PLURALIZE_RELATION_TYPE ` and ` JSON_API_FORMAT_RELATION_KEYS ` can be combined to
249249achieve different results.
250250
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+
251264### Meta
252265
253266You 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 1515REST_FRAMEWORK .update ({
1616 'PAGE_SIZE' : 1 ,
1717})
18+ JSON_API_POLYMORPHIC_ANCESTORS = (
19+ 'polymorphic.models.PolymorphicModel' ,
20+ )
Original file line number Diff line number Diff line change 2222 HyperlinkedRouterField = type (None )
2323
2424POLYMORPHIC_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 ,)
3528
3629
3730def get_resource_name (context ):
You can’t perform that action at this time.
0 commit comments