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

Add it to INSTALLED_APPS (Django auto‑config is supported, no settings needed):

INSTALLED_APPS = [
    ...
    "django_lastdayofmonth",
]

Compatibility matrix

Django version Python version Supported back‑ends
3.2 LTS → 5.0 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

# 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

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.0.0.tar.gz (5.8 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.0.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_lastdayofmonth-1.0.0.tar.gz
  • Upload date:
  • Size: 5.8 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.0.0.tar.gz
Algorithm Hash digest
SHA256 f1bd6b5c7f39294546bad2f7f4240b1558c5c3668927a37dbdf67fba101c4a10
MD5 3e2526ca60436d6cd52cbd2f1e0b879e
BLAKE2b-256 36fa1122ed75be7b5ba51fcda7a1f70cece467da99f3121732379c37d8f852da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_lastdayofmonth-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 609182b9555fe022b9b9c1be00be0d4ac3147b53d2a38d52808a50c310b9d42d
MD5 f3f97d828a7cc52e62378b1f58a75c83
BLAKE2b-256 c29786b4bf8de3c60d02e2e86e7e8efabf752002660fd5dc58aaf09929371578

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