gerard
unread,Sep 18, 2014, 9:59:55 AM9/18/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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