countryDri.py 1022 Bytes
Newer Older
1
from django.db import models
Florent Chehab's avatar
Florent Chehab committed
2
from backend_app.models.country import Country
3 4 5 6 7
from backend_app.models.abstract.basic_module import (
    BasicModule,
    BasicModuleSerializer,
    BasicModuleViewSet,
)
Florent Chehab's avatar
Florent Chehab committed
8
from backend_app.utils import get_model_config, get_viewset_permissions
9 10


11
class CountryDri(BasicModule):
12
    model_config = get_model_config("CountryDri")
13
    countries = models.ManyToManyField(Country, related_name="country_dri")
14

15 16 17 18
    @classmethod
    def get_serializer(cls):
        return CountryDriSerializer

19

20
class CountryDriSerializer(BasicModuleSerializer):
21 22
    class Meta:
        model = CountryDri
23
        fields = "__all__"
24 25


26
class CountryDriViewSet(BasicModuleViewSet):
27
    permission_classes = get_viewset_permissions("CountryDriViewSet")
28 29
    queryset = CountryDri.objects.all()  # pylint: disable=E1101
    serializer_class = CountryDriSerializer
30

31
    def get_queryset(self):
32
        country_id = self.kwargs["country_id"]
33
        return super().get_queryset().filter(countries__pk=country_id).distinct()