Django Timezone Utilities

0.15.0 · active · verified Fri Apr 17

`django-timezone-utils` provides a `TimeZoneField` for Django models, allowing storage and management of timezone information as strings (e.g., 'America/New_York'). It includes choices for displaying timezones and integrates seamlessly with Django's ORM and forms. The current version, 0.15.0, supports Django 4.x and Python 3, with releases typically aligning with new Django major versions.

Common errors

Warnings

Install

Imports

Quickstart

Define a Django model with a `TimeZoneField` to store timezone information. The `choices_display` argument (available from v0.15.0) simplifies how timezone choices are presented in forms.

from django.db import models
from timezone_utils.fields import TimeZoneField

class Event(models.Model):
    name = models.CharField(max_length=100)
    # Use TimeZoneField to store a timezone string, e.g., 'America/New_York'
    # The 'choices_display' argument requires django-timezone-utils >= 0.15.0.
    # For older versions, pass 'choices=TIMEZONE_CHOICES_STANDARD' instead.
    timezone = TimeZoneField(
        default="America/New_York",
        choices_display="WITH_GMT_OFFSET" # Or "STANDARD"
    )

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

view raw JSON →