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.0.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.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_lastdayofmonth-1.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 6fc257121a40ef68624c65fbce45631194d2807b3f422dd1e65bcce9dc276c98
MD5 02289873f21771358a5524259a6f8149
BLAKE2b-256 93fc18287ef7d18d1db204878abc095f600e1c5c6460e6fe027475b84c3eac71

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_lastdayofmonth-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 faee2fbf907996ae62b88a2d9282be38bacfe6013cd9ad69905e7645d4feb4e7
MD5 1d2641bfedfa502b81c898b626343bc9
BLAKE2b-256 be79371a00c2aee8dd843e095b3231048632b3c0879d7bba8ab5011b1797a9e2

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