import json

from django.contrib.contenttypes.fields import GenericRelation
from django.db import models

class TtStudentSet(models.Model):
    code = models.CharField(max_length=150)
    name = models.CharField(max_length=255)
    desc = models.TextField(null=True)
    department = models.ForeignKey("api.TtDepartment", on_delete=models.SET_NULL,null=True)
    academic_term = models.ForeignKey("api.TtAcademicTerm", on_delete=models.CASCADE)
    pos = models.ForeignKey("api.TtPos", on_delete=models.CASCADE, null=True)
    planned_size = models.IntegerField(null=True)
    status = models.SmallIntegerField()
    created_by = models.BigIntegerField(null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_by = models.BigIntegerField(null=True)
    updated_at = models.DateTimeField(auto_now=True)

    # having this line wont add column in db, it make the function like TtStaff.avoid_concurrency.add() can be used
    module = models.ManyToManyField("api.TtModule",through="api.TtStudentSetModule")
    activity = models.ManyToManyField("api.TtActivity",through="api.TtStudentSetActivity")
    student = models.ManyToManyField("api.TtStudent",through="api.TtStudentSetStudent",related_name="student_set")
    
    STATUS_TO_CODE = {
        "active": 1,
        "inactive": 2,
    }

    class Meta:
        db_table = "tt_student_set"

    def __str__(self):
        return self.name