offer.py 883 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from django.db import models
from rest_framework import serializers, viewsets, permissions
from rex.models.university import University
from rex.models.otherCore import Semester, Specialty


class Offer(models.Model):
    semester = models.ForeignKey(Semester, on_delete=models.PROTECT)
    university = models.ForeignKey(University, on_delete=models.PROTECT)
    nb_seats_offered = models.IntegerField()
    specialty = models.ManyToManyField(
        Specialty, related_name="has_seats_at_univ")

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


class OfferSerializer(serializers.ModelSerializer):
    class Meta:
        model = Offer
        fields = '__all__'


class OfferViewSet(viewsets.ModelViewSet):
    permission_classes = (permissions.IsAdminUser,)
    queryset = Offer.objects.all()  # pylint: disable=E1101
    serializer_class = OfferSerializer