Custom Django ORM expressions for datetime operations.
Project description
django-datetime-expressions
django-datetime-expressions provides custom expressions for Django ORM to simplify datetime operations. It allows relative additions and subtractions to datetime fields.
Features
- Perform relative operations on datetime fields (e.g., add/subtract days, weeks, months, years)
- Supports multiple database engines (MySQL, SQLite, Oracle)
- Extract epoch time using
EXTRACT
Installation
pip install django-datetime-expressions
Usage
Below is an example of using RelativeDay to manipulate dates.
from datetime import datetime
from django.db.models import F
from datetime_expressions import RelativeDay
# Example: Add 5 days to the current date
queryset = MyModel.objects.annotate(new_date=RelativeDay(F('date_field'), 5))
Supported Relative Operations
| Class Name | Description | Unit |
|---|---|---|
RelativeDay |
Add/Subtract days | Days |
RelativeWeek |
Add/Subtract weeks | 7-day units |
RelativeMonth |
Add/Subtract months | Months |
RelativeYear |
Add/Subtract years | Years |
RelativeHour |
Add/Subtract hours | Hours |
RelativeMinute |
Add/Subtract minutes | Minutes |
RelativeSecond |
Add/Subtract seconds | Seconds |
Extracting Epoch Time
Use the Epoch class to extract epoch time (seconds since January 1, 1970) from a datetime field.
from datetime_expressions import Epoch
queryset = MyModel.objects.annotate(epoch_time=Epoch(F('date_field')))
Supported Databases
- MySQL
- SQLite
- Oracle
Contribution
Bug reports and feature requests are welcome on GitHub Issues. Pull requests are also appreciated!
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_datetime_expressions-0.2.0.tar.gz.
File metadata
- Download URL: django_datetime_expressions-0.2.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26834284897f24470468e73c2f0a0205303adf13525acfafbced5350e24b41ac
|
|
| MD5 |
14e73d3cc588410f70c22f5739403a87
|
|
| BLAKE2b-256 |
748e1616372ab0227359c15fdb250eb579121b7c52c22955e5263e7e683ef207
|
Provenance
The following attestation bundles were made for django_datetime_expressions-0.2.0.tar.gz:
Publisher:
workflow.yml on towan912/django-datetime-expressions
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_datetime_expressions-0.2.0.tar.gz -
Subject digest:
26834284897f24470468e73c2f0a0205303adf13525acfafbced5350e24b41ac - Sigstore transparency entry: 186433382
- Sigstore integration time:
-
Permalink:
towan912/django-datetime-expressions@3a104790d5c32745308449bb89f47285b6ad1980 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/towan912
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@3a104790d5c32745308449bb89f47285b6ad1980 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file django_datetime_expressions-0.2.0-py3-none-any.whl.
File metadata
- Download URL: django_datetime_expressions-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a89bd84993061ce65473906b4dc1dfe6f14f29167060a64f912157158da2231
|
|
| MD5 |
80a2dcf077ca51a94faf10b7fd9a8891
|
|
| BLAKE2b-256 |
376598fe5566e256de7fa6fcac64ad79c15350b3686341e382b4b2eeb6c0d759
|
Provenance
The following attestation bundles were made for django_datetime_expressions-0.2.0-py3-none-any.whl:
Publisher:
workflow.yml on towan912/django-datetime-expressions
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_datetime_expressions-0.2.0-py3-none-any.whl -
Subject digest:
6a89bd84993061ce65473906b4dc1dfe6f14f29167060a64f912157158da2231 - Sigstore transparency entry: 186433383
- Sigstore integration time:
-
Permalink:
towan912/django-datetime-expressions@3a104790d5c32745308449bb89f47285b6ad1980 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/towan912
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@3a104790d5c32745308449bb89f47285b6ad1980 -
Trigger Event:
workflow_run
-
Statement type: