[Fixed]-Custom filter on contact by date – django rest framework

1πŸ‘

βœ…

I’m not sure if I’ve fully understood what you’re asking, but to filter a QuerySet to only display objects with a next_action_date in the future you can use:

import datetime
LeadContact.objects.filter(next_action_date__gte=datetime.date.today())

and to display only those with dates in the past use:

LeadContact.objects.filter(next_action_date__lte=datetime.date.today())

See this answer for a more detailed guide on filtering QuerySets by date. In particular, if the type of your next_action_date field is datetime, use datetime.datetime.now() rather than datetime.date.today(). More info also in the QuerySet docs.

πŸ‘€FraserES

Leave a comment