Skip to content

Instantly share code, notes, and snippets.

View tim-schilling's full-sized avatar

Tim Schilling tim-schilling

View GitHub Profile
@tim-schilling
tim-schilling / subquery_count.py
Created September 8, 2023 18:24
Subquery Count
from django.db.models import IntegerField, Subquery
class SubqueryCount(Subquery):
template = "(SELECT COUNT(*) FROM (%(subquery)s) _count)"
output_field = IntegerField()
@tim-schilling
tim-schilling / gist:827e3892ebbe5b82355f9a7257bc0f6d
Created June 21, 2023 14:12
Continuning 2023-2024 PSF Board nomination links
https://www.python.org/nominations/elections/2021-python-software-foundation-board/nominees/debora-azevedo/
https://www.python.org/nominations/elections/2021-python-software-foundation-board/nominees/tania-allard/
https://www.python.org/nominations/elections/2022-python-software-foundation-board/nominees/kushal-das/
https://www.python.org/nominations/elections/2022-python-software-foundation-board/nominees/jannis-leidel/
https://www.python.org/nominations/elections/2021-python-software-foundation-board/nominees/joannah-nanjekye/
https://www.python.org/nominations/elections/2022-python-software-foundation-board/nominees/dawn-wages/
https://www.python.org/nominations/elections/2022-python-software-foundation-board/nominees/simon-willison/
@tim-schilling
tim-schilling / admin.py
Last active November 11, 2022 16:38
Django admin annotate the page's objects rather than the queryset
# There will come a time when you want to show more information on the admin
# list view, but performing the annotation on the entire queryset kills
# performance. These classes will allow you to apply a QuerySet annotation
# to only those objects that are rendered on the current page.
# Constraints:
# - This adds one additional query to your request.
# - The annotated columns can't be used in ordering.
# - You need to define functions to access the annotated fields on the object.
Code coverage badges