Django Timezone Field

7.2.1 · active · verified Thu Apr 09

django-timezone-field is an actively maintained Django app that provides database, form, and Django REST Framework fields for handling `zoneinfo` and `pytz` timezone objects. It is currently at version 7.2.1 (released December 2025) and regularly updates to support the latest Django and Python versions. Its primary function is to simplify the storage and manipulation of timezone data within Django applications, abstracting away the complexities of `pytz` and the newer `zoneinfo` module.

Warnings

Install

Imports

Quickstart

Define a Django model with a `TimeZoneField` to store timezone objects. The field handles validation and conversion between string representations in the database and `zoneinfo.ZoneInfo` (or `pytz` timezone) objects in Python. You can set a default timezone using a string or a timezone object.

from django.db import models
from timezone_field import TimeZoneField

# For ZoneInfo (Python 3.9+ / modern Django) or pytz (older Django)
# You might need 'tzdata' installed for ZoneInfo if your system's timezone DB is incomplete.

class Event(models.Model):
    name = models.CharField(max_length=255)
    # Default behavior (uses zoneinfo on Django >= 5.x, pytz on older)
    timezone = TimeZoneField(default="UTC")

    # Example with explicit pytz usage (requires pytz installed if on >= 6.0)
    # For Django < 5.x, this field would default to use_pytz=True implicitly.
    # from pytz import timezone
    # explicit_pytz_tz = TimeZoneField(use_pytz=True, default=timezone('America/New_York'))

    # Example with choices_display for forms
    # from timezone_field.choices import WITH_GMT_OFFSET
    # display_timezone = TimeZoneField(choices_display=WITH_GMT_OFFSET)

    def __str__(self):
        return f"{self.name} ({self.timezone})"

# Example usage:
# event = Event.objects.create(name="Meeting", timezone="America/Los_Angeles")
# print(event.timezone) # Returns a zoneinfo.ZoneInfo or pytz.timezone object

view raw JSON →