offer.py 1.19 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2
from backend.models.university import University
Florent Chehab's avatar
Florent Chehab committed
3
from backend.models.other_core import Semester, Specialty
4
from backend.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
Florent Chehab's avatar
Florent Chehab committed
5
from backend.utils import get_model_config, get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
6 7


8
class Offer(MyModel):
Florent Chehab's avatar
Florent Chehab committed
9
    model_config = get_model_config("Offer")
Florent Chehab's avatar
Florent Chehab committed
10 11
    semester = models.ForeignKey(Semester, on_delete=models.PROTECT)
    university = models.ForeignKey(University, on_delete=models.PROTECT)
12 13 14 15 16 17

    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)

Florent Chehab's avatar
Florent Chehab committed
18 19 20 21 22 23 24
    specialty = models.ManyToManyField(
        Specialty, related_name="has_seats_at_univ")

    class Meta:
        unique_together = ('semester', 'university')


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


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