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.

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.7.tar.gz (17.2 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.7-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for django_pgsql_interval_field-0.9.7.tar.gz
Algorithm Hash digest
SHA256 f76536eacda01671d2a36af9286298a4045e7ec88c7609a351ef5cd92288aaf1
MD5 64a2a9efc049c850081466dcece579e9
BLAKE2b-256 bb1dd4945c9c27cecd48ae2388a1da382fdfd63208864a62cda1fe4c5020323f

See more details on using hashes here.

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

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.7-py3-none-any.whl.

File metadata

File hashes

Hashes for django_pgsql_interval_field-0.9.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8c787f280688b3a24a621c2fdd3f6864ba1a6d27c7f796669a419bd7a4c676e8
MD5 3ec8d7badad0aad6e13e95d01b698d46
BLAKE2b-256 92708e03aef66d7915b5d961449ae817a08ac33c71fe461934117fa130d068ea

See more details on using hashes here.

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

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