Time zones¶
Time zone support was added in Django 1.4, allowing you to store and handle local dates and times. It is highly recommended to store your time objects timezone-aware. Django handles this for you, but it does not provide a way for a user to save their timezone. This module adds support for this.
This module highly recommends you install pytz
along with it, but it is not required. By default, the module
uses the set of common timezones as reported by pytz.common_timezones
. If this is not available, the set as
provided by the CLDR is used instead.
The model field uses a datetime.tzinfo
Python object as representation, unless use_tzinfo is set to
False
. If pytz
is not available, setting use_tzinfo to False
is required, as it is not
possible to convert between timezone names and datetime.tzinfo
objects without it.
-
class
internationalflavor.timezone.models.
TimezoneField
(timezones=None, exclude=None, use_tzinfo=True, *args, **kwargs)¶ A model field that allows users to choose their timezone. By default, all timezones in the set of common timezones of pytz are available. Use the
timezones
argument to specify your own timezones, and useexclude
to exclude specific zones.If
use_tzinfo
isTrue
, an instance ofdatetime.tzinfo
is returned. This requirespytz
to be installed. Ifuse_tzinfo
isFalse
, a string is returned instead.
-
class
internationalflavor.timezone.forms.
TimezoneFormField
(timezones=None, exclude=None, *args, **kwargs)¶
See also
- Django: Time zones
- Django documentation on time zones