exchange.py 1.53 KB
Newer Older
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 28
from django.db import models
from backend_app.models.university import University
from base_app.models import User
from backend_app.fields import JSONField

from backend_app.models.abstract.base import BaseModel, BaseModelSerializer
from backend_app.models.shared import SEMESTER_OPTIONS


class Exchange(BaseModel):

    # This model should be filled with data from the ENT
    utc_univ_id = models.ForeignKey(University, on_delete=models.PROTECT)
    utc_departure_id = models.IntegerField()
    user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)

    year = models.PositiveIntegerField(default=2018)
    semester = models.CharField(max_length=5, choices=SEMESTER_OPTIONS, default="a")
    duration = models.PositiveIntegerField()
    dual_degree = models.BooleanField()
    master_obtained = models.BooleanField()
    student_major = models.CharField(max_length=20)
    student_minor = models.CharField(max_length=7)
    student_option = models.CharField(max_length=7)

    utc_allow_courses = models.BooleanField()
    utc_allow_login = models.BooleanField()

29
    # No specific validation of the JSON is required here
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    courses = JSONField(null=True)  # Store data from ENT


class ExchangeSerializer(BaseModelSerializer):
    class Meta:
        model = Exchange
        fields = BaseModelSerializer.Meta.fields + (
            "year",
            "semester",
            "duration",
            "dual_degree",
            "master_obtained",
            "student_major",
            "studentminor",
            "student_option",
        )