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
2
votes
2 answers

Django model manager queryset filter on aware datetime: no item display until server restart

I have a Django model which has a publication_date and an is_published fields. I've created a manager for this model which returns all published items which means: every item that has is_published=True and publication_date <= now. class…
Heyl1
  • 2,437
  • 3
  • 24
  • 31
2
votes
1 answer

Datetime objs will not come out correct when DST

I'm trying to import ical data to one of my Django apps. But it fail to consider DST (I think) so it show the time one hour wrong. If think this worked during winter time. This is a sample of importing the data: In [1]: from events.models import…
Niclas Nilsson
  • 5,691
  • 3
  • 30
  • 43
2
votes
2 answers

pytz alternative - using OS timezone as source?

Are there any simpler pytz alternative using OS timezone/dst as as source? a ctypes wrapper or something doesn't require compiling would be welcome. Edit: the beast
est
  • 11,429
  • 14
  • 70
  • 118
1
vote
1 answer

Time zone problem with Django's BaseDatabase cache expiry

I'm using Django's cache framework with the Database backend. In my settings I have USE_TZ=True, and the TIME_ZONE of my databases is set to: America/New_York. In my dev/testing environment, I'm using SQLite and Oracle in production both of which…
NDani
  • 21
  • 7
1
vote
1 answer

check if scheduled actions are due

I use huey to create scheduled tasks, that run for example every minute. I created an example to display my question: class Campaign(models.Model): active = models.BooleanField("active", default = True) name =…
xtlc
  • 1,070
  • 1
  • 15
  • 41
1
vote
2 answers

Why is timezone.now showing a future date when being applied as a default value to DateField in django

Here are the relevant settings in my project: settings.py TIME_ZONE = "US/Mountain" USE_TZ = True models.py (using timezone.now) class Submission(models.Model): date_created = models.DateField( default=timezone.now, blank=True, …
John R Perry
  • 3,916
  • 2
  • 38
  • 62
1
vote
1 answer

What is the correct way to convert Django date and time fields to current timezone?

I feel like I'm missing something obvious: I implemented timezones in my Django app using the SO solution here and it seems to be working (i.e. when the user changes to their timezone, Django's {% get_current_timezone as TIME_ZONE %} and…
Hermit
  • 35
  • 3
1
vote
1 answer

Is Django application affected by the server timezone?

I have the below settings: TIME_ZONE = UTC USE_TZ = True My server timezone is UTC+1 and the end user's timezone is UTC+2. Should I care about the server timezone or it is not related at all?
Yasser Mohsen
  • 1,411
  • 1
  • 12
  • 29
1
vote
2 answers

I want to change UTC time zone to Pakistan time zone in Django 4.1.2

This is my code below and it is not working LANGUAGE_CODE = 'en-us' TIME_ZONE = 'Asia/Pakistan' USE_I18N = True USE_L10N = True USE_TZ = True it is giving me this error A server error occurred. Please contact the administrator.
1
vote
0 answers

By default django saves UTC time into DB, I am trying to change it to IST timezone

Whenever a datetime field is updated it saves UTC time in DB. The problem is the DB I am using is used by multiple other applications/technologies. Other applications are using IST time to save the datetime. However coming to Django it saves the…
1
vote
1 answer

How to fix RuntimeWarning: DateTimeField Question.date_time received a naive datetime?

I want to delete 60 seconds old records but I am getting this error RuntimeWarning: DateTimeField Question.date_time received a naive datetime (2022-08-27 16:09:30.659947) while time zone support is active. def delete(self,request): …
1
vote
1 answer

How to show local time to the user in django?

I'm developing a Django app I have a model in which timestamps is added automatically. I want to show the time to the end users according to their local timezone. Here is my code: settings.py TIME_ZONE = 'UTC' USE_I18N = True USE_L10N =…
1
vote
1 answer

What is the difference between timezone.now and db.models.functions.Now?

Can anyone explain the difference between 'django.db.models.functions.Now' and 'django.utils.timezone.now'? For example, am I correct that functions.Now() returns the system time without timezone stamp, and timezone.now() would return UTC…
alias51
  • 8,178
  • 22
  • 94
  • 166
1
vote
1 answer

Django timezone.now() returning None

I know I could use auto_now_add equals True but it bugs me that I can't get this simple view to work. Here is the view: def create(request): if request.method == "POST": form = CreateListing(request.POST) if form.is_valid: …
1
vote
1 answer

Django Timezone Middleware Problems

I am trying to work with the Django Timezone Middleware which I took from the offical documentation, but it doesn't seem to work. I have a middleware.py file like this: import pytz from django.utils import timezone class TimezoneMiddleware: …
OptimusPrime
  • 777
  • 16
  • 25