Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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

today = date.today()
available_activities = Activity.objects.filter(
    available=True, date__gt=today
).order_by('date', 'start_time')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading