0
votes

I'm trying to retrieve all data between two dates (monday -> monday). Here's my code:

    some_day_last_week = datetime.datetime.now() - timedelta(days=7)
    monday_of_last_week = some_day_last_week - timedelta(days=(some_day_last_week.isocalendar()[2] - 1))
    monday_of_this_week = monday_of_last_week + timedelta(days=7)

    print "Someday last week %s" % some_day_last_week
    print "Monday of last week %s" % monday_of_last_week
    print "Monday of this week %s" % monday_of_this_week
    jobs = Jobs.objects.filter(created_time__gte=monday_of_last_week, created_time__lt=monday_of_this_week).order_by('-created_time')

    for job in jobs:
        print "Jobb: %s (%s)" % (job, job.created_time)

The output is fine, but I'm getting a RuntimeWarning which is bugging me. Here's that (as well as the other output):

Someday last week 2013-03-14 15:11:32.819508
Monday of last week 2013-03-11 15:11:32.819508
Monday of this week 2013-03-18 15:11:32.819508
xxx/venv/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2013-03-11 15:11:32.819508) while time zone support is active.

RuntimeWarning) xxx/venv/lib/python2.7/site-packages/django/db/models/fields/init.py:808: RuntimeWarning: DateTimeField received a naive datetime (2013-03-18 15:11:32.819508) while time zone support is active. RuntimeWarning) Jobb: Webdesigner (2013-03-13 09:14:02+00:00) [21/Mar/2013 15:11:32] "GET /jobs/feed/7days/ HTTP/1.1" 200 712

I have USE_TZ set to True in settings.py, and the field created_time is like this:

created_time = models.DateTimeField(_('Creation time'), default=datetime.now)

Anyone? :)

1

1 Answers

1
votes
jobs = Jobs.objects.filter(
    created_time__range[monday_of_last_week, monday_of_this_week]).order_by('-created_time')