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 @@ -423,6 +423,19 @@ field_name_mapping = {
423
423
```
424
424
425
425
426
+ ### Working with polymorphic resources
427
+
428
+ This package can defer the resolution of the type of polymorphic models instances to get the appropriate type.
429
+ 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.
430
+
431
+ Polymorphic ancestors must be defined on settings like this:
432
+
433
+ ``` python
434
+ JSON_API_POLYMORPHIC_ANCESTORS = (
435
+ ' polymorphic.models.PolymorphicModel' ,
436
+ )
437
+ ```
438
+
426
439
### Meta
427
440
428
441
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 27
27
HyperlinkedRouterField = type (None )
28
28
29
29
POLYMORPHIC_ANCESTORS = ()
30
- try :
31
- from polymorphic .models import PolymorphicModel
32
- POLYMORPHIC_ANCESTORS += (PolymorphicModel ,)
33
- except ImportError :
34
- pass
35
- try :
36
- from typedmodels .models import TypedModel
37
- POLYMORPHIC_ANCESTORS += (TypedModel ,)
38
- except ImportError :
39
- pass
30
+ for ancestor in getattr (settings , 'JSON_API_POLYMORPHIC_ANCESTORS' , ()):
31
+ ancestor_class = import_class_from_dotted_path (ancestor )
32
+ POLYMORPHIC_ANCESTORS += (ancestor_class ,)
40
33
41
34
42
35
def get_resource_name (context ):
You can’t perform that action at this time.
0 commit comments