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
4
votes
1 answer

Django get user timezone in template

I'm saving date in UTC. I wan't to change that date to automatic user timezone. my settings USE_TZ = True my template {% for sale in sales %} date : {{sale.date}} {% endfor %} I tried…
SAFEER N
  • 1,157
  • 2
  • 17
  • 30
4
votes
1 answer

Runtime Warning in django

I am working on a Django project with MySQL as the back-end, this warning keeps troubling me, can anyone please suggest a fix for this. Thanks in advance!! /usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py:808: …
Niranjan Sagar
  • 819
  • 1
  • 15
  • 17
3
votes
1 answer

How to handling timezones in django DRF without repeating myself too much?

Intro: My project TIME_ZONE is equal to 'UTC' while I have users from too many time zones. So, when I user make POST or PUT with date or time or dateTime fields I convert these fields to UTC before serializer.save(). Then, when a user make a GET…
3
votes
2 answers

Timezone It works locally but not in pythonanywhere (DJango)

I have a queryset to list today's sales from django.utils import timezone class VentaToday(ListView): queryset = Venta.objects.filter(fecha=timezone.now()).order_by('-id') template_name = 'venta/venta_today.html' In local, this works…
Piero Pajares
  • 276
  • 1
  • 4
  • 21
3
votes
0 answers

Django Unit test : `freeze_time` not work well in some cases (Seems like a bug..?)

This is my code for testing the role of TIME_ZONE and `USE_TZ: from django.test.utils import override_settings class TimeZoneTest(TestCase): @override_settings(TIME_ZONE='UTC', USE_TZ=True) @freeze_time("2018-01-04 13:30:55", tz_offset=9)…
user3595632
  • 5,380
  • 10
  • 55
  • 111
3
votes
1 answer

Replace "tzinfo" and print with localtime amends six minutes

I am creating a DataTimeField no time zone. Soon I am editing this TZ "manually" and then asking to read the value with local TZ. See the end result amends six minutes! Logic: >>> import datetime >>> from django.utils import timezone >>> test =…
3
votes
4 answers

Working with several time zone in Django

The application I am working on has as target users USA. And (as you may know) in USA there's more than one time zone. So I have some doubts: so how could I get the current time in server side based on the current user? And how could I store…
Gocht
  • 9,924
  • 3
  • 42
  • 81
3
votes
1 answer

Use different timezone for forms in django's admin site

I wonder if it is possible for django's admin site to accept two datetime fields of one model in two different timezones. For example suppose I have a model like: class A(models.Model): time_a = models.DateTimeField() time_b =…
zako
  • 285
  • 3
  • 10
3
votes
1 answer

Compare Postgresql timestamp to timezone in sql query in django

When I run the following query Viewed.objects.raw('SELECT "recently_viewed_viewed"."id"FROM "recently_viewed_viewed" WHERE NOT ("recently_viewed_viewed"."viewed_date" <= \'timezone.now()\' AND "recently_viewed_viewed"."user_id" = user_id)' ) I get…
robert
  • 819
  • 1
  • 10
  • 24
3
votes
0 answers

Django Timezone Conversion

I'm seeing some bizarre behavior in the log vs in the display. I can't figure it out. in settings.py: TIME_ZONE = 'America/Chicago' USE_TZ = True in views.py: local_timezone = pytz.timezone("America/Chicago") blast =…
Jesse Briggs
  • 148
  • 1
  • 7
3
votes
2 answers

How to fix Django error: " 'unicode' object has no attribute 'tzinfo' " on database read

I am deploying my Django project on Windows Azure. I was using SQLite as a database server and everything was ok. When I have deployed My project, I decided to connect it with an SQL Azure Database but it seems that this solution created some…
Wicem
  • 31
  • 1
  • 2
3
votes
2 answers

django time zone for printing date

I have django project with TIME_ZONE = 'America/Chicago' set in settings.py. I am using dates like this: from django.utils.dateparse import parse_datetime import datetime from datetime import datetime dateobject = parse_datetime(some_string) now =…
user606521
  • 14,486
  • 30
  • 113
  • 204
3
votes
1 answer

Django querying on range of days with timezone.now and __range broken?

I am running Django 1.4.3 and Python 2.7, with a PostgreSQL database (9.2.2). I have a model with a "last_view" field that is a timestamp of when a record is last viewed by a user. On my front page I want to display the ten most viewed items within…
user
  • 4,651
  • 5
  • 32
  • 60
2
votes
1 answer

RuntimeWarning: DateTimeField Model.date received a naive datetime while time zone support is active

I am trying to filter a query set to obtain this year's all posts. def thisYearQuerySet(objects): start_day = datetime.date(datetime.date.today().year, 1, 1) end_day = datetime.date(datetime.date.today().year, 12, 31) return…
Weilory
  • 2,621
  • 19
  • 35
2
votes
1 answer

How to display all datetime objects in a different timezone in Django

I am relatively new to Django. All of my datetime objects are in UTC and my settings.py file has TIME_ZONE = 'UTC' When these datetime objects show up in my html template using {{ obj.datetime }}, they are dislayed in UTC, I want to display them in…
bernardo
  • 173
  • 8
1 2
3
11 12