Thursday, September 18, 2014

problem with a date between a form and database

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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/541AE4F1.5060707%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment