problem with a date between a form and database

20 views
Skip to first unread message

gerard

unread,
Sep 18, 2014, 9:59:55 AM9/18/14
to django...@googlegroups.com
hello all,
i have a form to get a date. But when i get object from the database,
the database is not as expected, user type "18/09/2015", but after
savin, i got: 17/09/2015 22:00

here is the code:

#settings.py
TIME_ZONE = 'Europe/Paris'

#models.py
class MyEvent(models.Model):
dtstart = models.DateTimeField(auto_now=False, auto_now_add=False)

# forms.py
class UpdateAnnounceForm(forms.ModelForm):
dtstart = forms.DateField(widget=forms.DateInput(format = '%d/%m/%Y'),
input_formats=('%d/%m/%Y',))
class Meta:
model = MyEvent
def clean_dtstart(self):
return datetime.combine(self.cleaned_data['dtstart'],
datetime.min.time())


# views.py
if form.is_valid():
logger.debug("form %s" % form.cleaned_data)
form.save()
->
DEBUG 2014-09-18 15:42:48,169 views.py create_event 216 form {'dtstart':
datetime.datetime(2015, 9, 18, 0, 0, tzinfo=<DstTzInfo 'Europe/Paris'
CEST+2:00:00 DST>)}

# python manage.py shell
In [18]: evt=MyEvent.objects.get(id=39194)
In [19]: evt.dtstart
Out[19]: datetime.datetime(2015, 9, 17, 22, 0, tzinfo=<UTC>)

thanks in advance for help,


--
Gérard Henry

swie...@wellbridgehealth.com

unread,
Sep 18, 2014, 7:34:12 PM9/18/14
to django...@googlegroups.com
Timezones are hard.

Is USE_TZ=True in your settings?

I'd highly recommend starting on this page: https://docs.djangoproject.com/en/dev/topics/i18n/timezones/

Sid
Reply all
Reply to author
Forward
0 new messages