offer.py 1.08 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
3
4
5
6
7
from backend_app.models.specialty import Specialty
from backend_app.models.abstract.base import (
    BaseModel,
    BaseModelSerializer,
    BaseModelViewSet,
8
)
Florent Chehab's avatar
Florent Chehab committed
9
from backend_app.models import SEMESTER_OPTIONS
Florent Chehab's avatar
Florent Chehab committed
10
11


12
class Offer(BaseModel):
13

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

    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)

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


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


32
class OfferViewSet(BaseModelViewSet):
Florent Chehab's avatar
Florent Chehab committed
33
34
    queryset = Offer.objects.all()  # pylint: disable=E1101
    serializer_class = OfferSerializer