Here is how it looks like.
Written on top of django-timezone-field.
A Django app providing database and form fields for split datetime/time and pytz timezone objects.
Use
SplitDateTimeTimeZoneFieldin place offorms.DateTimeField.Use
SplitTimeTimeZoneFieldin place offorms.TimeField.
The setting USE_TZ_FIELDS = True will convert all admin.ModelAdmin to use SplitDateTimeTimeZoneField for models.DateTimeField and SplitTimeTimeZoneField for models.TimeField.
Requires USE_TZ = True in settings.py
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, \
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())
Installation
-
pip install django-datetimezone-field Add
timezone_fieldanddatetimezone_fieldto yoursettings.INSTALLED_APPS
INSTALLED_APPS = (
...
timezone_field,
datetimezone_field,
...
)
Running sample project
cd test/sample_projectvirtualenv sample-envsource sample-env/bin/activatepip install -r requirements.txtpython manage.py syncdbpython manage.py runserver
TODO
Unit tests
Found a Bug?
To file a bug or submit a patch, please head over to django-datetimezone-field on github.
Credits
Built on top of Mike Fogel’s django-timezone-field.
Metadata
Release files for django-datetimezone-field 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-datetimezone-field-0.1.8.tar.gz | 4.8 kB | Without provenance | Details |
Release files / django-datetimezone-field-0.1.8.tar.gz
| Download URL | django-datetimezone-field-0.1.8.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
113a3e34e49ab0d036fd57ad0556adf5a6d2be611362f68bab1b9c6be15bbeaa
|
|
BLAKE2b-256 checksum How to use checksums |
e7a23d19fb6efd83a560cd6f24db8b9ba9fd4726433935581cf91110bef6ee94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-datetimezone-field 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.