Questions tagged [django-timezone]

Timezone handling specific questions with Django

Saving, displaying time is complicated when there are multiple timezones involved. In version 1.4 django web-framework has provided a way to handle them better.

This tag helps to consolidate questions related to use of Django timezone handling.

Here is detail documentation : Time zones

179 questions
7
votes
1 answer

Two ways to create timezone aware datetime objects (Django). Seven minutes difference?

Up to now I thought both ways to create a timezone aware datetime are equal. But they are not: import datetime from django.utils.timezone import make_aware, get_current_timezone make_aware(datetime.datetime(1999, 1, 1, 0, 0, 0),…
guettli
  • 25,042
  • 81
  • 346
  • 663
7
votes
1 answer

Django Timezone Support Outside of Templates

Django's timezone-aware output apparently only applies when rendering a template. Is there a way to get that same auto-conversion to the currently active timezone for responses returning CSV or JSON?
Tom
  • 22,301
  • 5
  • 63
  • 96
7
votes
3 answers

Default value of DateTimeField for South migration in Django project with activated timezone support

I'm creating a schema migration with South 0.7.6 for my Django 1.4.3 project with enabled timezone support. The schema migration includes adding a DateTimeField (with auto_now=True) on one table. When creating the migration, South prompts me: The…
Henrik Heimbuerger
  • 9,924
  • 6
  • 56
  • 69
5
votes
2 answers

How do I get 1 day before timezone.now()

I have a button that should appear 1 day before the model object's start_date. In my view I have a functions that tells me if the object's start_date or end_date is now. def has_engagement(self): from rental.models import Inquiry …
Gabby Cervantes
  • 85
  • 2
  • 10
5
votes
2 answers

Django settings USE_TZ, TIME_ZONE and django rest framework

In Django tutorials, there is a sentence described like below. TIME_ZONE ... When USE_TZ is False, this is the time zone in which Django will store all datetimes. When USE_TZ is True, this is the default time zone that Django will use to…
nextdoordoc
  • 1,727
  • 6
  • 20
  • 30
5
votes
0 answers

Django filter - Hardcode timezone in url filter parameters

I use django filters backend along with Django rest for building a rest api. At certain endpoints the user can filter the request by datetime so this for example /api/api_endpoint_x/?time_start=2015-11-20 11:22:15.160983 would form a valid…
LetsPlayYahtzee
  • 7,161
  • 12
  • 41
  • 65
5
votes
1 answer

Django Admin NonExistentTimeError in date_hierarchy

I just got an error in Django Admin. This is the locally reproduced log: NonExistentTimeError at /admin/{blah}/ 2015-10-18 00:00:00 Request Method: GET Request URL: http://127.0.0.1:8000/admin/{blah}/?q=someuser%40hotmail.com Django Version:…
5
votes
2 answers

Django: Should I convert an aware datetime instance to UTC before posting to a model?

I have aware datetime instances (where tzinfo = "America/Los_Angeles") that I would like to save to a model. Should I convert it to UTC somehow before saving? Or can I just save it as is, since it's aware of its own timezone? Do I need to convert it…
sgarza62
  • 5,998
  • 8
  • 49
  • 69
4
votes
1 answer

how to serialize time with timezone in django-rest-framework's serializer?

I have a Django model: class Clinic(models.Model): NAME_MAX_LENGTH = 150 name = models.CharField(max_length=NAME_MAX_LENGTH,blank=False,null=False) start_at = models.DateTimeField(blank=False,default=timezone.now) the client sends the…
4
votes
3 answers

Django DateTimeField received a naive datetime while time zone support is active

I'm using Django 2.2 In my application, timezone support is enabled by USE_TZ=True in the settings file. I have models with DateTime field created. I need to filter data based on the date. The date can be provided by the user or else it will be…
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
4
votes
0 answers

Django non-UTC timezone aware dates in queryset

I'm running Django with Postgres. I want timezone-aware datetime objects returned from the database. I want all the datetimes in querysets to be set to the user's locale, not UTC. I can get timezone aware dates in querysets if I set USE_TZ=True in…
rgilligan
  • 754
  • 5
  • 18
4
votes
5 answers

How to show datetime in Django in specific timezone?

I have a Django (v1.10.6) project that has some models with datetime fields, for example: created_at = models.DateTimeField(auto_now_add=True) that are stored in PostgreSQL database without timezone information: created_at timestamp without time…
cansadadeserfeliz
  • 3,033
  • 5
  • 34
  • 50
4
votes
3 answers

return datetimes in the active timezone with a django query

I am trying to retrieve the last n hour rows from a table and print their datetimes in a given timezone, the timezone to use when printing dates is given, I am trying to use activate to make django return the datetimes with the proper timezone but…
Jesus Gomez
  • 1,460
  • 13
  • 30
4
votes
0 answers

Timezone aware DateTime fields in django forms

In short, I'm trying to show the user a DateTime field initialized with a timezone aware datetime object, allow them to edit it and post it back. Without doing anything special I get a warning about a non-timezone aware datetime being returned to…
jozxyqk
  • 16,424
  • 12
  • 91
  • 180
4
votes
1 answer

Django: activate() not showing effect

I have the following line in python manager.py shell: >>> import pytz >>> from django.utils import timezone >>> zone = "Asia/Kolkata" >>> timezone.activate(pytz.timezone(zone)) >>> timezone.now() datetime.datetime(2014, 12, 17, 1, 52, 0, 411937,…
chaitanya90
  • 697
  • 2
  • 8
  • 24
1
2
3
11 12