Skip to main content

django-pgsql-interval-field

Tests PyPI Python Django License

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 INTERVAL column; BIGINT fallback 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_value validation
  • 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.

Release files for django-pgsql-interval-field 0.9.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-pgsql-interval-field 0.9.7
File Size Uploaded
django_pgsql_interval_field-0.9.7.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-pgsql-interval-field 0.9.7
File Interpreter ABI Platform
django_pgsql_interval_field-0.9.7-py3-none-any.whl Python 3 none any Details

Total release size: 29.5 kB

Release files / django_pgsql_interval_field-0.9.7.tar.gz

Download URL django_pgsql_interval_field-0.9.7.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f76536eacda01671d2a36af9286298a4045e7ec88c7609a351ef5cd92288aaf1
BLAKE2b-256 checksum
How to use checksums
bb1dd4945c9c27cecd48ae2388a1da382fdfd63208864a62cda1fe4c5020323f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release files / django_pgsql_interval_field-0.9.7-py3-none-any.whl

Download URL django_pgsql_interval_field-0.9.7-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c787f280688b3a24a621c2fdd3f6864ba1a6d27c7f796669a419bd7a4c676e8
BLAKE2b-256 checksum
How to use checksums
92708e03aef66d7915b5d961449ae817a08ac33c71fe461934117fa130d068ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.7 This release

2 release files

0.9.6

2 release files

0.9.4

2 release files

0.9

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page