On Wed, Jan 6, 2016 at 11:06 PM, Ryan Causey <rccau...@gmail.com> wrote:

> 1. The documentation says that when USE_TZ = True that "Django stores
> datetime information in UTC in the database, uses time-zone-aware datetime
> objects internally, and translates them to the end user’s time zone in
> templates and forms." Does this mean that the TIME_ZONE setting in
> settings.py should be UTC? Or should it be the timezone in which the
> database server is located?
>

The particular needs of your project should determine how to configure
Django and your database server. Since you're asking here, let's assume you
do want to support users on multiple timezones.  You *should* configure
your database server's timezone to UTC in this case.  Now, for the Django
settings, a common scenario is that you want to display datetime
information to your users on *their* local timezone (which you can detect
and/or give them an option to set or store in their profile). For this, one
recommended approach is to store every datetime value in UTC, and only
convert to a specific timezone for user-display purposes. That's exactly
what USE_TZ = True is meant for.

>From the 1.8 docs, regarding the TIME_ZONE parameter, it states: "When
USE_TZ is True, this is the default time zone that Django will use to
display datetimes in templates and to interpret datetimes entered in
forms".  This means that, in the scenario described earlier, the value of
TIME_ZONE specified in settings.py will act just as a default for the
datetime conversion on user-display (templates, forms) and in
form-processing (in order to convert a datetime value from the user's
timezone to UTC).  You can customize the current timezone for the user's
session. See more information in
https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/

2. I am using a postgresql database, and the installation defaulted the
> database's timezone to my local one. In support of Django storing all
> datetime information in UTC in the database, does the database's timezone
> needs to be set to UTC? Or is it correct for the database's timezone to be
> the local one?
>

As said before, it's recommended that, in order to support multiple
timezone values in your database, you set the database server's timezone to
UTC. A local timezone on the server could get you into some trouble,
particularly if you are in a timezone with DST, and want to perform
datetime-related calculations later.


> 3. The documentation also says that one should use the UTC timezone in the
> code, and only convert to local time when dealing with end users. I take
> this to mean that in any code I write I should set tzinfo = UTC for all
> datetime objects I create programmatically and let Django translate them in
> forms and views to the end user's timezone automatically. Is this correct?
>

Read carefully the information on
https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/ (remember to
check the documentation specific to your Django version), it should help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGTC%2B7Zjb3XWZy4H54PxkNOoZ3anxFAEsWC28R5ac%2BHr_5ff3Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to