django-timezone

django DateTimeField with UTC offset?

一世执手 提交于 2020-01-12 06:54:27
问题 I have a model with a DateTimeField: deadline = models.DateTimeField(verbose_name="Valid unitl", null=True, blank=True) Users should be allowed to input date, time and timezone info in the field. This is my desired format: 2012-12-31 23:30 +0430 I expect the time will get converted to UTC before storing to db. So I tried using a model form for that, but it throws Enter a valid date/time. validation error on that DateTimeField if I enter the value above. This is in settings.py: DATE_INPUT

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

ε祈祈猫儿з 提交于 2019-12-29 08:00:07
问题 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 errors. I am no longer able to edit users profiles. I get always this error : AttributeError at /admin/auth/user/1/ 'unicode' object has no attribute 'tzinfo' 回答1: I had same issue trying to use django-pyodbc-azure database backend with Django (1.5.1):

Timezone.now() vs datetime.datetime.now()

女生的网名这么多〃 提交于 2019-12-21 07:15:18
问题 When should I be using django's timezone.now() and when should I be using python's datetime.datetime.now() . For example, in the following INSERT which would make more sense? - Product.objects.create(title='Soap', date_added=datetime.datetime.now()) - Product.objects.create(title='Soap', date_added=timezone.now()) Is there a rule of thumb on when to use each? 回答1: Just always use timezone.now() . Django now has timezone support which requires timezone 'aware' datetime objects. datetime.now()

django-timezone-field gets error unicode object has no attribute zone

丶灬走出姿态 提交于 2019-12-13 04:16:52
问题 I was not able to do a migration on one of my model objects that use django-timezone-field in django 1.7 I found a solution here: https://github.com/mfogel/django-timezone-field/issues/12 I installed the forked version of django-time-field which fixed this problem: https://github.com/mfogel/django-timezone-field/issues/12 I now get the error: unicode object has no attribute zone and 'unicode' object has no attribute 'localize' I am calling the field like this: timezone.activate(customer.time

Replace “tzinfo” and print with localtime amends six minutes

房东的猫 提交于 2019-12-11 08:36:30
问题 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 = datetime.datetime(2016, 9, 28, 10, 10, 10) datetime.datetime(2016, 9, 28, 10, 10, 10) >>> test = teste.replace(tzinfo=pytz.timezone('America/Sao_Paulo')) datetime.datetime(2016, 9, 28, 10, 10, 10, tzinfo=<DstTzInfo 'America/Sao_Paulo' LMT-1 day, 20:54

Django defaultfilters.date not timezone aware

半腔热情 提交于 2019-12-11 04:28:33
问题 Im trying to create a definition for django admin list_display, but the date filter is not timezone aware. If I just have the updated_date field in list_display, the time is correct. def get_edited_by(self): return u"%s %s - %s" % (self.edited_by.first_name, self.edited_by.last_name, defaultfilters.date(self.updated_date, 'SHORT_DATETIME_FORMAT')) The output is: Bob Bobson - 26.02.2014 18:27 (one hour off) The output from just the updated_date is: 26. februar 2014 19:27 (correct) Anyone know

DST timezone issue in django app

懵懂的女人 提交于 2019-12-11 03:19:27
问题 I am making an events app in django. In that I need to make a copy of one event object (row/entry in DB) into another. It creates another object with same details. This event object involves timezone and Day light Saving. I am facing problems during DST. I have applied time delta of 5 days during copying of objects. In normal days Event object 1 date: Nov. 10, 2014 10:36 a.m. Event object 2(copy of 1) date: Nov. 15, 2014 10:36 a.m. This OK..! But in DST days I don't want this 1 hr change.

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

眉间皱痕 提交于 2019-12-09 18:05:16
问题 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 field 'MyTable.my_field' does not have a default specified, yet is NOT NULL. Since you are adding this field, you MUST specify a default value to use for existing rows. Would you like to: 1. Quit now, and add a default to the field in models.py 2.