Screenshots - GradConnection/django-datetimezone-field GitHub Wiki

With USE_TZ_FIELDS=True, replacing the Django admin's AdminSplitDateTime widget:

Add form defaults to settings.TIME_ZONE

screen shot 2013-08-30 at 10 49 10 am

Change form defaults to the timezone of the date as stored in the database

SQLite only stores naive datetimes. Use Postgres to store timezone with dates.

screen shot 2013-08-30 at 10 49 02 am

Grappelli compatibility

screen shot 2013-08-30 at 10 48 32 am

Using the module in a typical Django view:

import pytz

from django import http
from django import forms
from django.utils import timezone
from django.forms.util import to_current_timezone
from django.conf import settings

from datetimezone_field import SplitDateTimeTimeZoneField, \
    SplitTimeTimeZoneField


def index(request):
    
    class MyForm(forms.Form):
        a_datetime = SplitDateTimeTimeZoneField()
        a_time = SplitTimeTimeZoneField()

    tz = pytz.timezone("Australia/Sydney")
    timezone.activate(tz)
    now = to_current_timezone(timezone.now()).replace(tzinfo=tz)

    my_form = MyForm(initial={
        'a_datetime': now,
        'a_time': now.time().replace(tzinfo=now.tzinfo)
    })

    return http.HttpResponse(my_form.as_p())

screen shot 2013-08-30 at 10 47 17 am