Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

figuring out objects created 30 min ago in django

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?

like image 927
user140736 Avatar asked Feb 28 '23 07:02

user140736


1 Answers

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.

like image 192
harto Avatar answered Mar 07 '23 20:03

harto