How do I change the filter in django to reflect not equal to?
15,786
Solution 1
Use the exclude
method. Details here.
open_slots = Opening.objects.filter(club_id=club_id, day=datetime.date.today()).exclude(reservation ='Open')
Solution 2
I have tried with following and it's working fine.
from django.db.models import Q
open_slots = Opening.objects.filter(~Q(reservation ='Open'),club_id=club_id, day=datetime.date.today() )
Author by
sharataka
Updated on June 20, 2022Comments
-
sharataka almost 2 years
I have the following filter:
open_slots = Opening.objects.filter(club_id=club_id, day=datetime.date.today(), reservation ='Open')
I want to create another list "closed_slots" that has all the same attributes as the above except that reservation is not equal to 'Open'. When I tried using reservation !='Open' I get an error. How do I fix this?