django‑lastdayofmonth

Cross‑database LastDayOfMonth
ORM function for Django.
Calculate the last calendar day of any month directly in the database, with the same API on SQLite, PostgreSQL, MySQL/MariaDB and Oracle.
Installation
pip install django-lastdayofmonth
That’s it — no settings tweaks required.
Simply import the helper wherever you need it (see Quick usage for an example).
Compatibility matrix
3.2 LTS → 5.2 LTS | 3.8 → 3.12 | SQLite, PostgreSQL ≥ 12, MySQL ≥ 5.7 / MariaDB ≥ 10.4, Oracle ≥ 19c |
The library is fully tested in CI across all the combinations above.
Quick usage
from django.db.models import DateField
from django_lastdayofmonth import LastDayOfMonth
Invoice.objects.annotate(
month_end=LastDayOfMonth("issued_date")
)
LastDayOfMonth
works in annotate()
, filter()
, aggregate()
, etc.
Why?
Calculating month‑end boundaries in Python causes heavy data transfer and breaks query optimisations. Leveraging the database engine keeps logic in SQL and stays performant.
Running tests locally
pip install tox pytest pytest-django dj-database-url mysqlclient oracledb psycopg2-binary
pytest -q --reuse-db
Use tox
to run the full matrix (tox -p auto
). See .github/workflows/ci.yml
for Docker examples of each database.
License
Released under the MIT license. See the LICENSE file for details.