offer.py 1.21 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2

3 4 5 6
from backend_app.models.abstract.base import (
    BaseModel,
    BaseModelSerializer,
    BaseModelViewSet,
7
)
8
from backend_app.models.shared import SEMESTER_OPTIONS
9 10 11
from backend_app.models.specialty import Specialty
from backend_app.models.university import University
from backend_app.permissions.app_permissions import ReadOnly
Florent Chehab's avatar
Florent Chehab committed
12 13


14
class Offer(BaseModel):
Florent Chehab's avatar
Florent Chehab committed
15
    university = models.ForeignKey(University, on_delete=models.PROTECT)
Florent Chehab's avatar
Florent Chehab committed
16 17
    year = models.PositiveIntegerField(default=2018)
    semester = models.CharField(max_length=2, choices=SEMESTER_OPTIONS, default="a")
18 19 20 21 22 23

    nb_seats_offered = models.PositiveIntegerField()
    # null => exchange not possible
    nb_seats_offered_exchange = models.PositiveIntegerField(null=True)
    nb_seats_offered_double_degree = models.PositiveIntegerField(null=True)

24
    specialties = models.ManyToManyField(Specialty, related_name="has_seats_at_univ")
Florent Chehab's avatar
Florent Chehab committed
25 26


27
class OfferSerializer(BaseModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
28 29
    class Meta:
        model = Offer
30
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
31 32


33
class OfferViewSet(BaseModelViewSet):
Florent Chehab's avatar
Florent Chehab committed
34 35
    queryset = Offer.objects.all()  # pylint: disable=E1101
    serializer_class = OfferSerializer
36 37
    permission_classes = (ReadOnly,)
    end_point_route = "offers"