offer.py 1.25 KB
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.university import University
Florent Chehab's avatar
Florent Chehab committed
3
from backend_app.models.other_core import Specialty
4 5 6 7 8
from backend_app.models.abstract.my_model import (
    MyModel,
    MyModelSerializer,
    MyModelViewSet,
)
Florent Chehab's avatar
Florent Chehab committed
9
from backend_app.utils import get_model_config, get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
10
from backend_app.models import SEMESTER_OPTIONS
Florent Chehab's avatar
Florent Chehab committed
11 12


13
class Offer(MyModel):
Florent Chehab's avatar
Florent Chehab committed
14
    model_config = get_model_config("Offer")
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(MyModelSerializer):
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(MyModelViewSet):
34
    permission_classes = get_viewset_permissions("OfferViewSet")
Florent Chehab's avatar
Florent Chehab committed
35 36
    queryset = Offer.objects.all()  # pylint: disable=E1101
    serializer_class = OfferSerializer