django-timezone

Runtime Warning in django

╄→尐↘猪︶ㄣ 提交于 2019-12-03 20:51:48
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: RuntimeWarning: DateTimeField received a naive datetime (2013-04-22 10:34:44) while time zone support is active. You have to make the following changes: In settings.py, you need to add following line: USE_TZ = True Also, in your code you should create aware datetime objects: eg: Instead of import datetime now = datetime.datetime.now() You should do: from django

How to format DateTimeField in Django Admin to localtime?

这一生的挚爱 提交于 2019-12-03 13:24:08
How to format DateTimeField in Admin according to localtime and timezone ? My settings.py: TIME_ZONE = 'Europe/Bratislava' LANGUAGE_CODE = 'en-us' USE_I18N = True USE_L10N = True USE_TZ = True pytz package is installed. model: class Material(models.Model): category = models.ForeignKey(Category, null=True, blank=True) code = models.CharField(max_length=10) description = models.CharField(max_length=30, blank=True, null=True) modified = models.DateTimeField(auto_now=True) created = models.DateTimeField(auto_now_add=True) Also tried some date formatting in settings, none of this changed the way

django DateTimeField with UTC offset?

自古美人都是妖i 提交于 2019-12-03 11:15:31
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_FORMATS = ('%Y-%m-%d %H:%M %Z', ) What am I missing? Edit: As per Видул Петров's suggestion, tried to use a

Django - How to run a function EVERYDAY?

蹲街弑〆低调 提交于 2019-12-03 07:20:19
I want to run this function everyday midnight to check expiry_date_notification. what can I do? I'm new to django and python. def check_expiry_date(request): products = Product.objects.all() for product in products: product_id = product.id expiry_date = product.expiry_date notification_days = product.notification_days check_date = int((expiry_date - datetime.datetime.today()).days) if notification_days <= check_date: notification = Notification(product_id=product_id) notification.save() As others have said, Celery can schedule tasks to execute at a specific time . from celery.schedules import

django's timezone.now does not show the right time

廉价感情. 提交于 2019-12-03 02:59:23
问题 My server is in London. In my settings.py I have: TIME_ZONE = 'Europe/Moscow' USE_TZ = True But when I do this: from django.utils import timezone print timezone.now().hour It prints London's time. What do I do wrong? UPDATE: >> timezone.now() datetime.datetime(2013, 4, 16, 12, 28, 52, 797923, tzinfo=<UTC>) tzinfo = <UTC> , so maybe it prints not London time, but UTC's +0 time? Anyway, how to make django show Moscow time? Also, when I render template with now = timezone.now() . {{ now.hour }}

django's timezone.now does not show the right time

谁都会走 提交于 2019-12-02 17:37:10
My server is in London. In my settings.py I have: TIME_ZONE = 'Europe/Moscow' USE_TZ = True But when I do this: from django.utils import timezone print timezone.now().hour It prints London's time. What do I do wrong? UPDATE: >> timezone.now() datetime.datetime(2013, 4, 16, 12, 28, 52, 797923, tzinfo=<UTC>) tzinfo = <UTC> , so maybe it prints not London time, but UTC's +0 time? Anyway, how to make django show Moscow time? Also, when I render template with now = timezone.now() . {{ now.hour }} prints, for example, 12 (London time) {{ now|date:"G" }} prints 16 (Moscow time) Daniel Hepper See

Why does time still show with UTC time zone instead of settings.TIME_ZONE?

北慕城南 提交于 2019-12-02 12:42:23
I have a model that shows a short string in __str__() method of the model def __str__(self): return "Scheduled at %s" % (self.date_time.strftime("%B %d %Y %I:%M %p")) #Output: <Task: Scheduled at September 30 2018 12:30 AM> # it should have been: <Task: Scheduled at September 29 2018 08:30 PM> When I go to the Django admin , I see in the title Task: Scheduled at September 30 2018 12:30 AM and in the input it is filled with the correct TIME_ZONE : 20:30:00 settings.py TIME_ZONE = 'Etc/GMT+4' USE_I18N = False USE_L10N = False USE_TZ = True He keeps showing time with UTC time zone, however I set

DateTimeField received a naive datetime

感情迁移 提交于 2019-11-30 17:17:33
I have model with DateTimeField column. I'm try to insert row with database current_time value directly into table by sql query. My sql query for MySQL database like: INSERT INTO MyTable (..., my_datetime, ...) VALUES (..., current_time, ...) And get: RuntimeWarning: DateTimeField ModelName.field_name received a naive datetime (2014-01-09 22:16:23) while time zone support is active. How to insert current time directly into table by sql query without warning? Further to falsetru's answer, if the datetime has already been created you can convert it to timezone aware: from django.utils import

DateTimeField received a naive datetime

半世苍凉 提交于 2019-11-30 00:47:31
问题 I have model with DateTimeField column. I'm try to insert row with database current_time value directly into table by sql query. My sql query for MySQL database like: INSERT INTO MyTable (..., my_datetime, ...) VALUES (..., current_time, ...) And get: RuntimeWarning: DateTimeField ModelName.field_name received a naive datetime (2014-01-09 22:16:23) while time zone support is active. How to insert current time directly into table by sql query without warning? 回答1: Further to falsetru's answer,

Django default=timezone.now() saves records using “old” time

蓝咒 提交于 2019-11-28 02:36:52
问题 This issue has been occurring on and off for a few weeks now, and it's unlike any that has come up with my project. Two of the models that are used have a timestamp field, which is by default set to timezone.now() . This is the sequence that raises error flags: Model one is created at time 7:30 PM Model two is created at time 10:00 PM, but in the MySQL database it's stored as 7:30 PM! Every model that is created has its time stamp saved under 7:30 PM, not the actual time, until a certain