countryDri.py 695 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
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
Florent Chehab's avatar
Florent Chehab committed
4
5


6
class CountryDri(Module):
7

8
    countries = models.ManyToManyField(Country, related_name="country_dri")
Florent Chehab's avatar
Florent Chehab committed
9
10


11
class CountryDriSerializer(ModuleSerializer):
Florent Chehab's avatar
Florent Chehab committed
12
13
    class Meta:
        model = CountryDri
14
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
15
16


17
class CountryDriViewSet(ModuleViewSet):
Florent Chehab's avatar
Florent Chehab committed
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()