Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
wiki2:python:django:tests [2018/10/12 15:52] alfred [self.client] |
wiki2:python:django:tests [2020/08/29 15:11] (actual) |
||
|---|---|---|---|
| Línea 66: | Línea 66: | ||
| self.assertEqual(mail.outbox[0].to[0], email) | self.assertEqual(mail.outbox[0].to[0], email) | ||
| </code> | </code> | ||
| + | |||
| + | |||
| + | ====== Articles ====== | ||
| + | |||
| + | ===== N+1 Queries ===== | ||
| + | |||
| + | Lets imagine you are creating a view for returning all the courses with some of their authors data. If you run a code like this: | ||
| + | <code python> | ||
| + | queryset = Course.objects.all() | ||
| + | courses = [] | ||
| + | for course in queryset: | ||
| + | courses.append({"title": course.title, "author": course.author.name}) | ||
| + | </code> | ||
| + | This is executing one query (for bringing all courses) and N queries more (one for each author). There is the library [[https://github.com/jmcarp/nplusone|nplusone]] to detect this. | ||
| + | * {{ :wiki2:python:django:automating_performance_testing_in_django.zip |}} | ||
| + | |||