views:

32

answers:

2

I have a DateTimeField called created in my model and I would like to get all the objects where created date is 30 min or more. How would query this using MyModel.objects(....) in django?

+1  A: 
.filter(created__lte=datetime.datetime.now() - datetime.timedelta(seconds=60 * 30))
Ignacio Vazquez-Abrams
+3  A: 

Maybe something like:

import datetime
created_time = datetime.datetime.now() - datetime.timedelta(minutes=30)
old_objects = MyModel.objects.filter(created__lte=created_time)

See http://docs.djangoproject.com/en/dev/topics/db/queries/ for more information on creating queries, filtering, etc.

harto