[Answered ]-How to check the filter object is returning any data or not in Django

1👍

I think you can use this :

if not checkroom:
    # Do this...
else:
    # Do that...

0👍

You have to use exists query which is faster then retrieve a row.

is_exists_room = Rooms.objects.filter(building_id=building_id, room_no=room_no).exists()

if not is_exists_room:
    print("The room doesn't exist!")

Leave a comment