Categories
Python Answers

How to filter query objects by date range in Python Django?

Spread the love

To filter query objects by date range in Python Django, we can use the filter method.

For instance, we write

Sample.objects.filter(date__range=["2021-01-01", "2021-01-31"])

to call objects.filter with the date__range parameter set to a list with the date range with the strings as the date values.

date is the column name we’re filtering by.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *