I have a model
models.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils import timezone
class Article(models.Model):
sort = models.IntegerField(blank=True)
pub_date = models.DateTimeField(default=timezone.now)
title = models.CharField(max_length=30, blank=True)
common.py
TIME_ZONE = 'America/New_York'
USE_TZ = True
local.py
from .common import *
CELERY_BROKER_URL = env('REDIS_URL')
CELERY_RESULT_BACKEND = env('REDIS_URL')
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = TIME_ZONE
production.py
from .common import *
CELERY_BROKER_URL = env('REDIS_URL')
CELERY_RESULT_BACKEND = env('REDIS_URL')
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = TIME_ZONE
tasks.py
from __future__ import absolute_import, unicode_literals
from celery.decorators import task
from .models import Article
import urllib2
import json
import datetime
@task(name="articles")
def update_article():
# .... more code
article = Article.objects.get(id=1)
if article != None:
article.pub_date = datetime.datetime.now()
article.title = "Hello"
article.save()
When I run in the django shell
import datetime
pub_date = datetime.datetime.now()
print pub_date
The pub_date is EST / 'America/New_York' timezone - correct.
I have a celery to update the Article, I wrote a simple code
article.pub_date = datetime.datetime.now()
When the pub_date is updated, in the DB the date is in UTC not America/New_York / EST timezone, even the shell is showing me correct ETC, but running it with the task, in the postgres DB it is UTC