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
@@ -1,7 +1,7 @@
1
1
2
2
# Lab 2
3
3
4
-
Let's kick it up a notch with some [Django Debug Toolbar](https://github.com/jazzband/django-debug-toolbar/)!
4
+
Let's kick it up a notch with some [Django Debug Toolbar](https://github.com/django-commons/django-debug-toolbar/)!
5
5
6
6
## Lab 2.1
7
7
@@ -17,7 +17,7 @@ The site seems to be running slower lately. Please make the site fast again!
17
17
18
18
To reproduce:
19
19
1. Browse to the [posts page](http://127.0.0.1:8000/p/).
20
-
1. Browse to a [post's page](http://127.0.0.1:8000/p/author-up-language-push-162/).
20
+
1. Browse to a [post's page](http://127.0.0.1:8000/p/term-writer-recognize-race-available-5291/).
21
21
1. Browse to the [posts admin page](http://127.0.0.1:8000/admin/newsletter/post/).
22
22
1. Why are these slow?
23
23
@@ -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,7 +302,7 @@ 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)
305
+
- You can use the [docs](https://docs.djangoproject.com/en/stable/ref/models/querysets/#id9)
306
306
or inspect [the code](https://github.com/django/django/blob/stable/4.1.x/django/db/models/aggregates.py#L145-L149)
307
307
(right click on ``Count``and choose "Go To Definition") in
0 commit comments