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

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

django_pgsql_interval_field-0.9.6.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_pgsql_interval_field-0.9.6-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file django_pgsql_interval_field-0.9.6.tar.gz.

File metadata

File hashes

Hashes for django_pgsql_interval_field-0.9.6.tar.gz
Algorithm Hash digest
SHA256 cca28bbf55b3f153dc6d5abdc7058ca69688f75f325dc93c8122d724e8581aad
MD5 39a288d5b21414e2a045bd0221e618b1
BLAKE2b-256 ce2493f0b17fe27f99e1d497b3a391490beda9f1f78f51842828c720e6eb43eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_pgsql_interval_field-0.9.6.tar.gz:

Publisher: publish.yml on mpasternak/django-interval-field

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_pgsql_interval_field-0.9.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_pgsql_interval_field-0.9.6-py3-none-any.whl
Algorithm Hash digest
SHA256 95fae826c7597d0bd033876a10ac1b01f668275c8fe2b2e364993bea2e246cfc
MD5 66e4150bfa571aebd9096f25cc74ceed
BLAKE2b-256 f797de942ed1384afa362c243cd5d922bc71e76573fdce2fb358b18f0145fb71

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_pgsql_interval_field-0.9.6-py3-none-any.whl:

Publisher: publish.yml on mpasternak/django-interval-field

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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