You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/querying_data.md
+15-18Lines changed: 15 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,7 +113,8 @@ If you want to retrieve user's `id`, `username` and `location` fields but under
113
113
...
114
114
]
115
115
```
116
-
<br/>
116
+
117
+
117
118
118
119
`GET /users/?query={id, username, groups{name}}`
119
120
```js
@@ -389,7 +390,6 @@ class CourseSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
389
390
}
390
391
]
391
392
```
392
-
<br/>
393
393
394
394
`GET /course/?query={name, related_books{title}}`
395
395
```js
@@ -403,7 +403,7 @@ class CourseSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
403
403
}
404
404
]
405
405
```
406
-
<br/>
406
+
407
407
408
408
## DynamicFieldsMixin kwargs
409
409
`DynamicFieldsMixin` accepts extra kwargs in addition to those accepted by a serializer, these extra kwargs can be used to do more customizations on a serializer as explained below.
@@ -494,19 +494,18 @@ From the response above you can see that `author` field has been excluded fom bo
494
494
!!! note
495
495
`fields` and `exclude` kwargs have no effect when you access the resources directly, so when you access books you will still get all fields i.e
496
496
497
-
`GET /books/`
498
-
```js
499
-
[
500
-
{
501
-
"id":1,
502
-
"title":"Computer Programming Basics",
503
-
"author":"S.Mobit"
504
-
},
505
-
...
506
-
]
507
-
```
508
-
So you can see that all fields have appeared as specified on `fields = ['id', 'title', 'author']` on BookSerializer class.
509
-
<br/>
497
+
`GET /books/`
498
+
```js
499
+
[
500
+
{
501
+
"id": 1,
502
+
"title": "Computer Programming Basics",
503
+
"author": "S.Mobit"
504
+
},
505
+
...
506
+
]
507
+
```
508
+
Yo you can see that all fields have appeared as specified on `fields = ['id', 'title', 'author']` on BookSerializer class.
510
509
511
510
512
511
### query kwarg
@@ -645,7 +644,6 @@ class CourseSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
645
644
]
646
645
```
647
646
So you can see that on a nested field `books` pks have been returned instead of books data as specified on `return_pk=True` kwarg on `BookSerializer`.
648
-
<br/>
649
647
650
648
651
649
### disable_dynamic_fields kwarg
@@ -686,7 +684,6 @@ class CourseSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
686
684
]
687
685
```
688
686
So you can see that even though the query asked for only `title` field under `books`, all fields have been returned, so this means fields filtering has applied on `CourseSerializer` but not on `BookSerializer` because we used `disable_dynamic_fields=True` on it.
0 commit comments