Published: 09 Dec 2018 › Updated: 09 Dec 2018

Django’s new Extract*() classes
Django 1.10 and even more 1.11 comes with convenient methods for annotating date parts to your query.
Django comes with these methods in terms of date manipulating
- ExtractYear
- ExtractMonth
- ExtractDay
- ExtractWeekDay
- ExtractWeek
and with these in terms of time
- ExtractHour
- ExtractMinute
- ExtractSecond
Then you can go like:
from django.db.models.functions import ExtractWeek
my_query.annotate(week=ExtractWeek(“created”))
Here is link to the docs.
Thank you!
Leave Django’s new Extract*() classes to:
Read more #python posts
Best Posts From n1
We have not curated any of n1-cz's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From n1
- How to mount host share directory in Virtualbox Linux system
- Project documentation aka own wiki(ish) docs
- How to publish a package to PyPI
- Postgres and date subtracting
- Twitter on blockchain
- Docker + your development and production environments
- Django’s new Extract*() classes
- Docker + SQLite 3
- Vue.js - init a component inside a component programmatically
- Gunicorn — autoreload app