counter.py 1.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
from rest_framework import serializers
from rest_framework.response import Response
from rest_framework.decorators import list_route

from counter.models import Counter

from api.views import RightModelViewSet


class CounterSerializer(serializers.ModelSerializer):

    is_open = serializers.BooleanField(read_only=True)
    barman_list = serializers.ListField(
Sli's avatar
Sli committed
14
15
        child=serializers.IntegerField(),
        read_only=True
16
17
18
19
    )

    class Meta:
        model = Counter
Sli's avatar
Sli committed
20
21
        fields = ('id', 'name', 'type', 'club',
                  'products', 'is_open', 'barman_list')
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39


class CounterViewSet(RightModelViewSet):
    """
        Manage Counters (api/v1/counter/)
    """

    serializer_class = CounterSerializer
    queryset = Counter.objects.all()

    @list_route()
    def bar(self, request):
        """
            Return all bars (api/v1/counter/bar/)
        """
        self.queryset = self.queryset.filter(type="BAR")
        serializer = self.get_serializer(self.queryset, many=True)
        return Response(serializer.data)