Django queryset with True values excluded

I am tryig to build a queryset where only the false values are added.

Models

Models
reference = models.CharField(validators=[MinLengthValidator(15)], max_length=25, primary_key=True)
h0730 = models.BooleanField(default=False)
h0800 = models.BooleanField(default=False)
h0830 = models.BooleanField(default=False)
h0900 = models.BooleanField(default=False)
h0930 = models.BooleanField(default=False)
h1000 = models.BooleanField(default=False)
h1030 = models.BooleanField(default=False)
h1100 = models.BooleanField(default=False)
h1130 = models.BooleanField(default=False)
h1200 = models.BooleanField(default=False)
h1230 = models.BooleanField(default=False)
h1300 = models.BooleanField(default=False)
h1330 = models.BooleanField(default=False)
h1400 = models.BooleanField(default=False)
h1430 = models.BooleanField(default=False)
h1500 = models.BooleanField(default=False)
h1530 = models.BooleanField(default=False)
delivery_date = models.CharField(max_length=8)
is_cancelled = models.BooleanField(default=False)

Views

taken_slots = Order.objects.filter(delivery_date__exact=delivery_date).filter(reference__icontains=code).filter(is_cancelled=False)

slots_remaining = ['h0730', 'h0800', 'h0830', 'h0900', 'h0930', 'h1000', 'h1030', 'h1100', 'h1130', 'h1200', 'h1230', 'h1300', 'h1330', 'h1400', 'h1430', 'h1500', 'h1530']

for slot in taken_slots:
	if slot.h0730 and 'h0730' in slots_remaining:
		slots_remaining.remove('h0730')
	if slot.h0800 and 'h0800' in slots_remaining:
		slots_remaining.remove('h0800')
		...
		...

The above for loop works as is expected but I am trying to optimize the process. For example if there are 100 references for the day, “taken_slots” will will be iterated 100 times.

The expected output after the for loop completes is that the “slots_remaining” list will only have the False values remaining.

#############################################################

To add a bit more context, an example of a queryset for one reference would be something like this:

<QuerySet [{'h0730': True, 'h0800': False, 'h0830': False, 'h0900': False, 'h0930': False, 'h1000': False, 'h1030': False, 'h1100': False, 'h1130': False, 'h1200': False, 'h1230': False, 'h1300': False, 'h1330': False, 'h1400': True, 'h1430': True, 'h1500': True, 'h1530': True}]>

but this is what I would like to get:

<QuerySet [{'h0800': False, 'h0830': False, 'h0900': False, 'h0930': False, 'h1000': False, 'h1030': False, 'h1100': False, 'h1130': False, 'h1200': False, 'h1230': False, 'h1300': False, 'h1330': False}]>

#############################################################

What I am trying to accomplish is basically a merge of all values for multiple references. For example, the 6 references below would be part of a single query set

ref_start = ['h0730', 'h0800', 'h0830', 'h0900', 'h0930', 'h1000', 'h1030', 'h1100', 'h1130', 'h1200', 'h1230', 'h1300', 'h1330', 'h1400', 'h1430', 'h1500', 'h1530']

ref1 = ['True', 'h0800', 'h0830', 'True', 'h0930', 'h1000', 'h1030', 'h1100', 'h1130', 'h1200', 'h1230', 'h1300', 'h1330', 'h1400', 'h1430', 'h1500', 'h1530']
ref2 = ['h0730', 'h0800', 'h0830', 'h0900', 'True', 'h1000', 'h1030', 'h1100', 'h1130', 'h1200', 'h1230', 'h1300', 'h1330', 'h1400', 'h1430', 'h1500', 'h1530']
ref3 = ['h0730', 'h0800', 'h0830', 'h0900', 'h0930', 'h1000', 'True', 'h1100', 'h1130', 'h1200', 'h1230', 'h1300', 'h1330', 'h1400', 'h1430', 'h1500', 'h1530']
ref4 = ['h0730', 'h0800', 'h0830', 'h0900', 'h0930', 'h1000', 'h1030', 'h1100', 'h1130', 'h1200', 'True', 'h1300', 'h1330', 'h1400', 'h1430', 'h1500', 'h1530']
ref5 = ['h0730', 'h0800', 'h0830', 'h0900', 'h0930', 'h1000', 'h1030', 'h1100', 'h1130', 'h1200', 'h1230', 'True', 'True', 'h1400', 'h1430', 'h1500', 'h1530']
ref6 = ['h0730', 'h0800', 'h0830', 'h0900', 'h0930', 'h1000', 'h1030', 'h1100', 'h1130', 'h1200', 'h1230', 'h1300', 'h1330', 'h1400', 'h1430', 'True', 'h1530']

ref_merged = ['True', 'h0800', 'h0830', 'True', 'True', 'h1000', 'True', 'h1100', 'h1130', 'h1200', 'True', 'True', 'h1330', 'h1400', 'h1430', 'True', 'h1530']

ref_merged_without_True = ['h0800', 'h0830', 'h1000', 'h1100', 'h1130', 'h1200', 'h1330', 'h1400', 'h1430', 'h1530']

Is it possible to get ref_merged_without_True directly from the query or is looping necessary?

My first and second reactions to this are that I’d be looking at a different design for my models. While I don’t know the application you’re trying to build or what your actual requirements are, I can’t help but think “there’s got to be a better way”.

I’m going to make the guess that this is intended to be some type of “delivery scheduling” application, where you’re trying to track the time slots that are available in the future. You’re creating one row for each delivery, where that delivery occupies one (or more) time slots.

The purpose of your query here then is to determine what time slots are available on a given day.

Am I close?

If so, it seems to me that you’re going to be a lot better off if you were to keep one separate calendar object rather than spreading the calendar data across “N” different customers.

Hello Ken.

Yes, you are correct about this part been for delivery scheduling and timeslot availability. Your deduction skills are top notch :).

I did realize after posting that maybe I went a bit to complicated in my original design so have started to rethink the database and other project structures but the single calendar object you mention will most likely also clear up a lot of headaches in the future.

Luckily, the project is still in its early stages so it wont be much of a hassle to make those changes.

Sorry for wasting your time but thank you for taking the time to reply.