'>' not supported between instances of 'type' and 'datetime.date'

Question:

I’m creating a CRUD application that displays activities available on or after today; I’m working through the filtering mechanism on displaying these activities, however I’m having a nightmare trying to only show the activities that are on/after today.

I’m getting the below error when I try to use the ‘>=’ operand, however it’s giving me the following error:

'>' not supported between instances of 'type' and 'datetime.date'

Below is my views.py for the comparison:

today= date.today()
available_activities = Activity.objects.filter(available = True).values()
activities = available_activities.filter(date > today).values()
activities= available_activities.order_by('date','start_time')

Below is a screenshot of the error traceback also, to show the data format for the data in the DB also.
enter image description here

Asked By: Claire

||

Answers:

You can filter with the __gt lookup [Django-doc] so:

today = date.today()
available_activities = Activity.objects.filter(
    available=True, date__gt=today
).order_by('date', 'start_time')
Answered By: Willem Van Onsem
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.