Skip to main content

Cross-database LastDayOfMonth function for Django ORM

Project description

django‑lastdayofmonth

PyPI PyPI - Python Version CI License: MIT

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

Django version Python version Supported back‑ends
3.2 LTS 3.8 → 3.12 SQLite, PostgreSQL ≥ 12, MySQL ≥ 5.7 / MariaDB ≥ 10.4, Oracle ≥ 19c
4.2 LTS → 5.2 LTS 3.8 → 3.13 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

# annotate each invoice with the month‑end date of its `issued_date`
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  # install testing and DB driver dependencies
pytest -q --reuse-db                 # run tests locally (requires pytest configuration in pyproject.toml)

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_lastdayofmonth-1.2.1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_lastdayofmonth-1.2.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file django_lastdayofmonth-1.2.1.tar.gz.

File metadata

  • Download URL: django_lastdayofmonth-1.2.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for django_lastdayofmonth-1.2.1.tar.gz
Algorithm Hash digest
SHA256 dda744a35777fba7d00d89020871e59718655ca125a490bc4446e53201ee8368
MD5 27d70a99bb5e20deb1c0e58394f2556a
BLAKE2b-256 82380a9e8bf5221be0728bd3da3ec8842da45f9169e888ee66c335f28703008b

See more details on using hashes here.

File details

Details for the file django_lastdayofmonth-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_lastdayofmonth-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 469aeb2578a7487089aeeb8d849a4890782c5553a8e7f6b5d715841e9cfc2886
MD5 c374094f1a443b04a4886ef599d6e4b6
BLAKE2b-256 696400ae8e8577658051a7f1f1a3a5d0abb72af77e6c038d0f550b2e65cd53b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page