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: README.md
+25-14Lines changed: 25 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ class MovieSerializer(serializers.ModelSerializer):
65
65
66
66
```
67
67
68
-
Note that for proper performance and functionality, all nested serializers must have a corresponding `prefetch_related` on the queryset used by `MovieSerializer`. Also, the `nomination_count` field should be `annotate`d on it. Therefore, you'll need to write this complex chain of nested prefetches:
68
+
For good performance and correct functionality, all nested serializers must have a corresponding `prefetch_related` on the queryset used by `MovieSerializer`. Also, the `nomination_count` field should be `annotate`d on it. Therefore, you'll need to write this complex chain of nested prefetches:
69
69
70
70
```python
71
71
from django.db.models import Prefetch
@@ -120,31 +120,42 @@ class VirtualMovie(v.VirtualModel):
120
120
121
121
classMeta:
122
122
model = Movie
123
-
124
-
qs = VirtualMovie().get_optimized_queryset(
125
-
Movie.objects.all(),
126
-
lookup_list=[
127
-
"directors__awards",
128
-
"directors__nomination_count",
129
-
]
130
-
)
131
123
```
132
124
133
-
If, for example, you forget to add the `nomination_count` field on `VirtualPerson`, the following exception will appear when using `MovieSerializer`:
If you aren't using DRF serializers, you hydrate your queryset with *virtual fields* manually:
150
+
151
+
```python
152
+
qs = VirtualMovie().get_optimized_queryset(
153
+
Movie.objects.all(),
154
+
lookup_list=[
155
+
"directors__awards",
156
+
"directors__nomination_count",
157
+
]
158
+
)
148
159
```
149
160
150
161
To learn more, check the [Installation](https://vintasoftware.github.io/django-virtual-models/installation/) and the [Tutorial](https://vintasoftware.github.io/django-virtual-models/tutorial/).
0 commit comments