Friday, January 11, 2013

Re: DateTimeField received a naive datetime (2013-01-10 00:00:00) while time zone support is active.

On Fri, Jan 11, 2013 at 8:23 AM, Jeff Hsu <jyhsu1125@gmail.com> wrote:
> Hi all,
>
> I kept getting DateTimeField received a naive datetime (2013-01-10
> 00:00:00) while time zone support is active. but I can't figure out where
> it's receiving a naive datetime. I have USE_TZ set to True in my setting
> file(stores timezone aware object in mysql?). My url is as below:
>
> urlpatterns = patterns('django.views.generic.date_based', #add the
> repetitive pattern here
> url(r'^$', 'archive_index', entry_info_dict,
> name='coltrane_entry_archive_index'),
> url(r'^(?P<year>\d{4})/$','archive_year', entry_info_dict,
> name='coltrane_entry_archive_year'),
> url(r'^(?P<year>\d{4})/(?P<month>\w{3})/$','archive_month',
> entry_info_dict,
> name='coltrane_entry_archive_month'),
> url(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/$','archive_day',
> entry_info_dict,
> name='coltrane_entry_archive_day'),
>
> url(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$',
> 'object_detail', entry_info_dict, name='coltrane_entry_detail'),
> #the forth arg will this patter a name
> #[-\w] will match letter, number or a hyphen
> )
>
> Every time I access a detail page from the archive index page, the error
> will pop out. I'm using generic view to do my detail page, and I can figure
> out what's wrong. Can anybody give me some direction?
>
> http://dpaste.com/871999/
>
> Thank you,
> Jeff
>

Function based generic views were deprecated in 1.3, TZ support
appeared in 1.4.

When a date based generic view is asked to filter against a
DateTimeField, it takes the specified day, and filters that field is
between datetime.combine(date, time.min) and datetime.combine(date,
time.max). datetime.combine only returns TZ aware datetimes if the
time supplied is TZ aware (time.min/time.max are not).

I suggest you update to use the class based generic views that arrived in 1.3:

https://docs.djangoproject.com/en/1.4/topics/generic-views-migration/

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate