I have a Django model that defines a TimeSlot. Each TimeSlot can hold a certain number of users (TimeSlot.spots
). Each TimeSlot also has a certain number of users already held in it (a many to many field, TimeSlot.participants
.
When I pass to the template that displays the available TimeSlots to the user, I annotate with TimeSlot.objects.annotate(Count('participants'))
,which gives the number of users currently held by the TimeSlot as participants__count
.
However, what I really want is the number of spots remaining, the capacity (TimeSlot.spots
) minus the number currently held (participants__count
). How can I annotate another field with this new number, so I can pass it to the template?