django-pgsql-interval-field
An INTERVAL model field for Django, backed by PostgreSQL's native INTERVAL
type (and stored as BIGINT microseconds on other backends). Values are
exposed in Python as datetime.timedelta.
Why?
PostgreSQL has a native INTERVAL column type for storing durations, but
Django ships no model field that maps to it. IntervalField fills that gap:
on PostgreSQL it uses the native INTERVAL type, and on other backends it
stores the duration as a BIGINT number of microseconds — so the same model
works everywhere while taking advantage of PostgreSQL where available.
Features
- Native PostgreSQL
INTERVALcolumn;BIGINTfallback for other backends (MySQL, SQLite, …) - Maps to
datetime.timedelta - Configurable form widget with per-unit inputs (days/hours/minutes/seconds/
microseconds) plus
min_value/max_valuevalidation - Internationalized (ships Polish and German translations)
- Optional Dojango widget support
- Example/test Django project included
Supported versions
Tested in CI against these Django × Python combinations:
| Django | 3.10 | 3.11 | 3.12 | 3.13 | 3.14 |
|---|---|---|---|---|---|
| 5.2 LTS | ✓ | ✓ | ✓ | ✓ | ✓ |
| 6.0 | — | — | ✓ | ✓ | ✓ |
| 6.1 | — | — | ✓ | ✓ | ✓ |
Installation
Using uv (recommended)
uv add django-pgsql-interval-field
Using pip
pip install django-pgsql-interval-field
Add "interval" to INSTALLED_APPS to pick up the widget's CSS and the
bundled translations.
Quick start
from datetime import timedelta
from django.db import models
from interval.fields import IntervalField
class Meeting(models.Model):
# Stored as PostgreSQL INTERVAL, or BIGINT microseconds elsewhere.
duration = IntervalField(default=timedelta(hours=1))
# Restrict the form widget's units and range.
break_time = IntervalField(
format="HMS",
min_value=timedelta(minutes=5),
max_value=timedelta(hours=2),
null=True,
blank=True,
)
Assign datetime.timedelta values (or a raw number of microseconds, or a
"[D day[s], ]HH:MM:SS[.ffffff]" string); reading the field always returns a
timedelta.
License
MIT — see LICENSE for details.
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_pgsql_interval_field-0.9.7.tar.gz.
File metadata
- Download URL: django_pgsql_interval_field-0.9.7.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f76536eacda01671d2a36af9286298a4045e7ec88c7609a351ef5cd92288aaf1
|
|
| MD5 |
64a2a9efc049c850081466dcece579e9
|
|
| BLAKE2b-256 |
bb1dd4945c9c27cecd48ae2388a1da382fdfd63208864a62cda1fe4c5020323f
|
Provenance
The following attestation bundles were made for django_pgsql_interval_field-0.9.7.tar.gz:
Publisher:
publish.yml on mpasternak/django-interval-field
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_pgsql_interval_field-0.9.7.tar.gz -
Subject digest:
f76536eacda01671d2a36af9286298a4045e7ec88c7609a351ef5cd92288aaf1 - Sigstore transparency entry: 2367175473
- Sigstore integration time:
-
Permalink:
mpasternak/django-interval-field@4bbd823f503a9e2be83b6a423dca5a6a681525c4 -
Branch / Tag:
refs/tags/0.9.7 - Owner: https://github.com/mpasternak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4bbd823f503a9e2be83b6a423dca5a6a681525c4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_pgsql_interval_field-0.9.7-py3-none-any.whl.
File metadata
- Download URL: django_pgsql_interval_field-0.9.7-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c787f280688b3a24a621c2fdd3f6864ba1a6d27c7f796669a419bd7a4c676e8
|
|
| MD5 |
3ec8d7badad0aad6e13e95d01b698d46
|
|
| BLAKE2b-256 |
92708e03aef66d7915b5d961449ae817a08ac33c71fe461934117fa130d068ea
|
Provenance
The following attestation bundles were made for django_pgsql_interval_field-0.9.7-py3-none-any.whl:
Publisher:
publish.yml on mpasternak/django-interval-field
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_pgsql_interval_field-0.9.7-py3-none-any.whl -
Subject digest:
8c787f280688b3a24a621c2fdd3f6864ba1a6d27c7f796669a419bd7a4c676e8 - Sigstore transparency entry: 2367175612
- Sigstore integration time:
-
Permalink:
mpasternak/django-interval-field@4bbd823f503a9e2be83b6a423dca5a6a681525c4 -
Branch / Tag:
refs/tags/0.9.7 - Owner: https://github.com/mpasternak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4bbd823f503a9e2be83b6a423dca5a6a681525c4 -
Trigger Event:
release
-
Statement type: