countryDri.py 695 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
from backend_app.models.abstract.module import Module, ModuleSerializer, ModuleViewSet
4 5


6
class CountryDri(Module):
7

8
    countries = models.ManyToManyField(Country, related_name="country_dri")
9 10


11
class CountryDriSerializer(ModuleSerializer):
12 13
    class Meta:
        model = CountryDri
14
        fields = "__all__"
15 16


17
class CountryDriViewSet(ModuleViewSet):
18 19
    queryset = CountryDri.objects.all()  # pylint: disable=E1101
    serializer_class = CountryDriSerializer
20

21
    def get_queryset(self):
22
        country_id = self.kwargs["country_id"]
23
        return super().get_queryset().filter(countries__pk=country_id).distinct()