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
1
vote
1 answer

How to get the original local machine time zone in a Django application?

In Django you have a TIME_ZONE setting, which, as I understand, somehow patches the standard date and time packages in runtime, making them think the application is working in the time zone specified. As a result, generic Python methods for…
greatvovan
  • 2,439
  • 23
  • 43
1
vote
0 answers

Why django changes timezone while creating Post Model?

def test_post_order_positioning_by_date(self): Post.objects.create( body="test", date_added="2020-12-31 18:51:19.959463+01:00", author=self.user, uniqueID="61672dba-0d36-43b1-b36a-bbd0a3d317b5", image="" …
hen
  • 65
  • 1
  • 7
1
vote
0 answers

Django how to compare correctly against django.utils.timezone.localtime and PostgreSQL time with time zone?

I have a legacy PostgreSQL table with time with time zone column. in models.py I have the filed set to models.TimeField I want to compare accessed Django.utils.timezone.localtime() with db_field_time_with_time_zone I have tried below: # let's say…
XJOJIX
  • 117
  • 2
  • 7
1
vote
2 answers

How to save and use timezones in Django

I have an important question. I understand Django saves data in "localtime", that is, UTC for my international app. So, if a user creates an "Event" with startdate (datetime object) 18:00, it will be 18:00 UTC. However, the user lives in Spain…
Alejandro Veintimilla
  • 10,743
  • 23
  • 91
  • 180
1
vote
1 answer

Django: Filter for month with timezone (after switching from SQLite to PostgreSQL)

In preparation for deployment, I switched from SQLite to PostgreSQL (following this advice). Now I have some trouble filtering certain items for timestamp by month which I didn't have before with SQLite. The problem is, that I get the items of the…
Ralf Zosel
  • 683
  • 1
  • 7
  • 26
1
vote
1 answer

Django Time Zone issue

I'm having lot's of troubles with TimeZones in my Django application. For explanation purposes I'll jump right to the example : I have an object which has a TimeField(null=True, blank=True), and I basically want to show this time depending on the…
dev.ink
  • 380
  • 5
  • 21
1
vote
0 answers

Store Datetime field in localtime in Django

I use Django 3 with postgresql. USE_TZ is False and TIME_ZONE is 'Asia/Baku'. django.utils.timezone.now() correctly return Baku localtime, but all DateTimeFields with auto_now_add save datetime in UTC in database. I want to use localtime everywhere…
AlexMercer
  • 301
  • 3
  • 10
1
vote
0 answers

Using local timezone in django admin template

After crying under my desk for a while over this problem I got the courage to come on SO and ask this question. I have a django model: entry_time = models.DateTimeField(auto_now_add=True) On my admin change_form.html and change_list.html I would…
Austin
  • 103
  • 10
1
vote
1 answer

Django | Datetime's time changes when doing the query

I am trying to query between a range of dates. Looking at the query that Django generates, I see that it is not taking the time from the datetime This is my code tz = pytz.timezone('Europe/London') today = datetime.now(tz=tz) …
user12545838
1
vote
1 answer

Postgres doesn't store system time in the database

I am using docker-compose for a registration form, where the api and database reside in separate containers. The response on registration shows system date and time, which I wanted, but in postgres date field shows incorrect data, and I don't know…
1
vote
1 answer

Count events types per day for different timezones using Django ORM

We have a table that holds multiple events and when they were added. The default timezone used for storing the events is UTC. Eg : class Events: type = models.CharField(max_length=45, null=False) date_added =…
1
vote
0 answers

Django timezone converting doesn't work on DateTimeField with values_list

I'm trying implement user based timezone to my Django app. I activated user timezone in middleware. In normal queries (like filter(),all()) everything is ok. In response, I can see timezone awarded data like that: {"modified":…
kamilyrb
  • 2,502
  • 3
  • 10
  • 25
1
vote
0 answers

Querying datetime object in django doesn't work because of time zone

I'm facing the issue of wrong query result due to timezone issue. I've read several answers, but most of them suggest USE_TZ = False. But we can't do that because of several dependencies on time zone. blog =…
Krishna
  • 6,107
  • 2
  • 40
  • 43
1
vote
1 answer

Django - TIME_ZONE and timezone.now()

I've the following settings:- TIME_ZONE = 'Asia/Kolkata' USE_I18N = True USE_L10N = True USE_TZ = True Also, I've set auto_now = True in my DateTimeField's. However, the datetime that gets saved in the column in of UTC (ie -5:30 hours). I have…
Praful Bagai
  • 16,684
  • 50
  • 136
  • 267
1
vote
1 answer

Django does not seem to account for DayLightSavings

In my models I want to update the last_edited value of the Submission object everytime the UserAnwser object is saved. To this end I've written the following code from django.utils import timezone ... class UserAnswer(models.Model): answer =…
Jasper
  • 2,131
  • 6
  • 29
  • 61