Skip to main content

A Django app providing database and form fields for split datetime/time and pytz timezone objects.

Project description

# django-datetimezone-field

Written on top of `django-timezone-field`.

A Django app providing database and form fields for split datetime/time and pytz timezone objects.

* Use `SplitDateTimeTimeZoneField` in place of `forms.DateTimeField`.
* Use `SplitTimeTimeZoneField` in place of `forms.TimeField`.

The setting `USE_TZ_FIELDS = True` will convert all `admin.ModelAdmin`s to use
`SplitDateTimeTimeZoneField` for `models.DateTimeField`s and `SplitTimeTimeZoneField` for `models.TimeField`s.

Requires `USE_TZ = True`

## Note

If using a database that does not support timezone-aware times then the initial values of model forms will always be in the UTC timezone.

## Form Field

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, \

def index(request):

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

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

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

return http.HttpResponse(my_form.as_p())

## Installation

1. `pip install django-timezone-field`
2. `pip install django-datetimezone-field`
3. Add `datetimezone_field` to your `settings.INSTALLED_APPS`



## Running sample project

1. `cd test/sample_project`
2. `virtualenv sample-env`
3. `source sample-env/bin/activate`
4. `pip install -r requirements.txt`
5. `python syncdb`
6. `python runserver`


* Unit tests

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-datetimezone-field, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size django-datetimezone-field-0.1.tar.gz (4.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page