README.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. django-timezone-field
  2. =====================
  3. .. image:: https://img.shields.io/travis/mfogel/django-timezone-field/develop.svg
  4. :target: https://travis-ci.org/mfogel/django-timezone-field/
  5. .. image:: https://img.shields.io/coveralls/mfogel/django-timezone-field/develop.svg
  6. :target: https://coveralls.io/r/mfogel/django-timezone-field/
  7. .. image:: https://img.shields.io/pypi/dm/django-timezone-field.svg
  8. :target: https://pypi.python.org/pypi/django-timezone-field/
  9. A Django app providing database and form fields for `pytz`__ timezone objects.
  10. Examples
  11. --------
  12. Database Field
  13. ~~~~~~~~~~~~~~
  14. .. code:: python
  15. import pytz
  16. from django.db import models
  17. from timezone_field import TimeZoneField
  18. class MyModel(models.Model):
  19. timezone1 = TimeZoneField(default='Europe/London') # defaults supported
  20. timezone2 = TimeZoneField()
  21. timezone3 = TimeZoneField()
  22. my_inst = MyModel(
  23. timezone1='America/Los_Angeles', # assignment of a string
  24. timezone2=pytz.timezone('Turkey'), # assignment of a pytz.DstTzInfo
  25. timezone3=pytz.UTC, # assignment of pytz.UTC singleton
  26. )
  27. my_inst.full_clean() # validates against pytz.common_timezones
  28. my_inst.save() # values stored in DB as strings
  29. tz = my_inst.timezone1 # values retrieved as pytz objects
  30. repr(tz) # "<DstTzInfo 'America/Los_Angeles' PST-1 day, 16:00:00 STD>"
  31. Form Field
  32. ~~~~~~~~~~
  33. .. code:: python
  34. from django import forms
  35. from timezone_field import TimeZoneFormField
  36. class MyForm(forms.Form):
  37. timezone = TimeZoneFormField()
  38. my_form = MyForm({
  39. 'timezone': 'America/Los_Angeles',
  40. })
  41. my_form.full_clean() # validates against pytz.common_timezones
  42. tz = my_form.cleaned_data['timezone'] # values retrieved as pytz objects
  43. repr(tz) # "<DstTzInfo 'America/Los_Angeles' PST-1 day, 16:00:00 STD>"
  44. Installation
  45. ------------
  46. #. From `pypi`__ using `pip`__:
  47. .. code:: sh
  48. pip install django-timezone-field
  49. #. Add `timezone_field` to your `settings.INSTALLED_APPS`__:
  50. .. code:: python
  51. INSTALLED_APPS = (
  52. ...
  53. 'timezone_field',
  54. ...
  55. )
  56. Changelog
  57. ------------
  58. * 3.0 (2018-09-15)
  59. * Support django 1.11, 2.0, 2.1
  60. * Add support for python 3.7
  61. * Change default human-readable timezone names to exclude underscores
  62. (`#32`__ & `#37`__)
  63. * 2.1 (2018-03-01)
  64. * Add support for django 1.10, 1.11
  65. * Add support for python 3.6
  66. * Add wheel support
  67. * Support bytes in DB fields (`#38`__ & `#39`__)
  68. * 2.0 (2016-01-31)
  69. * Drop support for django 1.7, add support for django 1.9
  70. * Drop support for python 3.2, 3.3, add support for python 3.5
  71. * Remove tests from source distribution
  72. * 1.3 (2015-10-12)
  73. * Drop support for django 1.6, add support for django 1.8
  74. * Various `bug fixes`__
  75. * 1.2 (2015-02-05)
  76. * For form field, changed default list of accepted timezones from
  77. `pytz.all_timezones` to `pytz.common_timezones`, to match DB field
  78. behavior.
  79. * 1.1 (2014-10-05)
  80. * Django 1.7 compatibility
  81. * Added support for formating `choices` kwarg as `[[<str>, <str>], ...]`,
  82. in addition to previous format of `[[<pytz.timezone>, <str>], ...]`.
  83. * Changed default list of accepted timezones from `pytz.all_timezones` to
  84. `pytz.common_timezones`. If you have timezones in your DB that are in
  85. `pytz.all_timezones` but not in `pytz.common_timezones`, this is a
  86. backward-incompatible change. Old behavior can be restored by
  87. specifying `choices=[(tz, tz) for tz in pytz.all_timezones]` in your
  88. model definition.
  89. * 1.0 (2013-08-04)
  90. * Initial release as `timezone_field`.
  91. Running the Tests
  92. -----------------
  93. #. Install `tox`__.
  94. #. From the repository root, run
  95. .. code:: sh
  96. tox
  97. Postgres will need to be running locally, and sqlite will need to be
  98. installed in order for tox to do its job.
  99. Found a Bug?
  100. ------------
  101. To file a bug or submit a patch, please head over to `django-timezone-field on github`__.
  102. Credits
  103. -------
  104. Originally adapted from `Brian Rosner's django-timezones`__. The full list of contributors is available on `github`__.
  105. __ http://pypi.python.org/pypi/pytz/
  106. __ http://pypi.python.org/pypi/django-timezone-field/
  107. __ http://www.pip-installer.org/
  108. __ https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
  109. __ https://github.com/mfogel/django-timezone-field/issues/32
  110. __ https://github.com/mfogel/django-timezone-field/issues/37
  111. __ https://github.com/mfogel/django-timezone-field/issues/38
  112. __ https://github.com/mfogel/django-timezone-field/issues/39
  113. __ https://github.com/mfogel/django-timezone-field/issues?q=milestone%3A1.3
  114. __ https://tox.readthedocs.org/
  115. __ https://github.com/mfogel/django-timezone-field/
  116. __ https://github.com/brosner/django-timezones/
  117. __ https://github.com/mfogel/django-timezone-field/graphs/contributors