add Seat annotations

This commit is contained in:
Mira Weller
2024-07-22 12:10:37 +02:00
parent f26a67029a
commit 40492d1408
2 changed files with 22 additions and 6 deletions
+14 -4
View File
@@ -972,9 +972,19 @@ class ItemMetaPropertiesSerializer(I18nAwareModelSerializer):
class SeatSerializer(I18nAwareModelSerializer):
has_order = serializers.BooleanField()
has_cart = serializers.BooleanField()
has_voucher = serializers.BooleanField()
class Meta:
model = Seat
read_only_fields = ('id', 'subevent', 'zone_name', 'row_name', 'row_label',
'seat_number', 'seat_label', 'seat_guid', 'product', 'sorting_rank', 'x', 'y',)
fields = ('id', 'subevent', 'zone_name', 'row_name', 'row_label',
'seat_number', 'seat_label', 'seat_guid', 'product', 'blocked', 'sorting_rank', 'x', 'y',)
read_only_fields = (
'id', 'subevent', 'zone_name', 'row_name', 'row_label',
'seat_number', 'seat_label', 'seat_guid', 'product', 'sorting_rank', 'x', 'y',
'has_order', 'has_cart', 'has_voucher',
)
fields = (
'id', 'subevent', 'zone_name', 'row_name', 'row_label',
'seat_number', 'seat_label', 'seat_guid', 'product', 'blocked', 'sorting_rank', 'x', 'y',
'has_order', 'has_cart', 'has_voucher',
)
+8 -2
View File
@@ -674,10 +674,16 @@ class SeatViewSet(ConditionalListView, viewsets.ModelViewSet):
queryset = Seat.objects.none()
write_permission = 'can_change_event_settings'
filter_backends = [DjangoFilterBackend]
filterset_fields = ['zone_name', 'row_name', 'row_label', 'seat_number', 'seat_label', 'seat_guid', 'blocked']
filterset_fields = ['subevent',
'zone_name', 'row_name', 'row_label', 'seat_number', 'seat_label',
'seat_guid', 'blocked',]
def get_queryset(self):
return self.request.event.seats.all()
if self.request.event.has_subevents:
subevent = self.request.event.subevents.get(pk=self.request.GET.get('subevent'))
return Seat.annotated(event_id=self.request.event.id, subevent=subevent, qs=subevent.seats.all())
else:
return Seat.annotated(event_id=self.request.event.id, subevent=None, qs=self.request.event.seats.all())
def perform_update(self, serializer):
super().perform_update(serializer)