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/lab2.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,14 +62,14 @@ is a never ending, relentless battle.
62
62
63
63
#### Post listing admin
64
64
The admin page suffers from a [N+1 problem](https://ddg.gg?q=N%2B1+django) and
65
-
needs to make use of [``prefetch_related``](https://docs.djangoproject.com/en/4.1/ref/models/querysets/#django.db.models.query.QuerySet.prefetch_related)
65
+
needs to make use of [``prefetch_related``](https://docs.djangoproject.com/en/stable/ref/models/querysets/#django.db.models.query.QuerySet.prefetch_related)
66
66
since it renders each category of the post on the page. This can be chained on
67
67
the QuerySet by overriding ``ModelAdmin.get_queryset``. The need for
68
68
``prefetch_related`` is evident from the 100 duplicated queries that are fetching data from the table
69
69
``newsletter_post_categories``. That table is the intermediate table used with
70
70
a ``models.ManyToManyField``. There is a slight wrinkle in that the categories
71
71
are being rendered in order of the categories' titles. In order to push that
72
-
to the database, you must use a [``Prefetch``](https://docs.djangoproject.com/en/4.1/ref/models/querysets/#django.db.models.Prefetch)
72
+
to the database, you must use a [``Prefetch``](https://docs.djangoproject.com/en/stable/ref/models/querysets/#django.db.models.Prefetch)
73
73
object that specifies:
74
74
75
75
```python
@@ -164,7 +164,7 @@ squeeze all the speedy goodness out of the application.
164
164
165
165
That said, consider the application(s) you work on. What are the most
166
166
frequently used parts? What do you have in place to catch slowness?
167
-
Could you benefit from using [``assertNumQueries(...)``](https://docs.djangoproject.com/en/4.1/topics/testing/tools/#django.test.TransactionTestCase.assertNumQueries)?
167
+
Could you benefit from using [``assertNumQueries(...)``](https://docs.djangoproject.com/en/stable/topics/testing/tools/#django.test.TransactionTestCase.assertNumQueries)?
168
168
169
169
170
170
## Lab 2.2
@@ -302,12 +302,12 @@ Let's consider what we know:
302
302
count.
303
303
- This can be fixed by using an appropriate ``GROUPBY`` clause in the SQL.
304
304
- What does the Django ORM's ``Count`` expression offer in terms of parameters?
305
-
- You can use the [docs](https://docs.djangoproject.com/en/4.1/ref/models/querysets/#id9)
306
-
or inspect [the code](https://github.com/django/django/blob/stable/4.1.x/django/db/models/aggregates.py#L145-L149)
305
+
- You can use the [docs](https://docs.djangoproject.com/en/stable/ref/models/querysets/#id9)
306
+
or inspect [the code](https://github.com/django/django/blob/stable/5.2.x/django/db/models/aggregates.py#L159-L163)
307
307
(right click on ``Count``and choose "Go To Definition") in
308
308
your IDEif you're using PyCharm or VSCode.
309
309
- We can see that ``Count`` subclasses [``Aggregate`` which has ``distinct``as
310
-
a param](https://github.com/django/django/blob/e151df24ae2b0a388fc334a6f1dcb31110d5819a/django/db/models/aggregates.py#L25-L35).
310
+
a param](https://github.com/django/django/blob/stable/5.2.x/django/db/models/aggregates.py#L26-L33).
0 commit comments