Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fed0bf6

Browse files
Updated docs to include model resource_name
1 parent 008f4df commit fed0bf6

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

‎docs/usage.md‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ per request via the `PAGINATE_BY_PARAM` query parameter (`page_size` by default)
3636

3737
### Setting the resource_name
3838

39-
You may manually set the `resource_name` property on views or serializers to
40-
specify the `type` key in the json output. It is automatically set for you as the
41-
plural of the view or model name except on resources that do not subclass
39+
You may manually set the `resource_name` property on views, serializers, or
40+
models to specify the `type` key in the json output. In the case of setting the
41+
`resource_name` property for models you must include the property inside a
42+
`JSONAPIMeta` class on the model. It is automatically set for you as the plural
43+
of the view or model name except on resources that do not subclass
4244
`rest_framework.viewsets.ModelViewSet`:
45+
46+
47+
Example - `resource_name` on View:
4348
``` python
4449
class Me(generics.GenericAPIView):
4550
"""
@@ -56,6 +61,23 @@ If you set the `resource_name` property on the object to `False` the data
5661
will be returned without modification.
5762

5863

64+
Example - `resource_name` on Model:
65+
``` python
66+
class Me(models.Model):
67+
"""
68+
A simple model
69+
"""
70+
name = models.CharField(max_length=100)
71+
72+
class JSONAPIMeta:
73+
resource_name = "users"
74+
```
75+
If you set the `resource_name` on a combination of model, serializer, or view
76+
in the same hierarchy, the name will be resolved as following: view >
77+
serializer > model. (Ex: A view `resource_name` will always override a
78+
`resource_name` specified on a serializer or model)
79+
80+
5981
### Inflecting object and relation keys
6082

6183
This package includes the ability (off by default) to automatically convert json

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /