[Django]-Django query: How to filter objects by todays day, time and after 30 minutes?

3👍

You have used used TimeField in your model declaration. That stores only the time with no data for day, month or year.

A time, represented in Python by a datetime.time instance

So instead of using datetime.now() use datetime.now().time() and instead of datetime.now() + timedelta(minutes=30) use (datetime.now() + timedelta(minutes=30)).time()

To be able to include filtering by day, month, year and time replace TimeField in the model with DateTimeField. The filtering using datetime.now() and the timedelta(minutes=30) will work as in your original question.

Leave a comment