File size: 1,679 Bytes
b7a7f32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from core.config import settings
from core.db import Base
from sqlalchemy import (
    Boolean,
    Column,
    Integer,
    SmallInteger,
    String,
    ForeignKey,
    DateTime,
    Date,
)
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import relationship


class User(Base):
    id = Column(Integer, primary_key=True, index=True)
    profile_image = Column(String(100))
    full_name = Column(String, index=True)
    email = Column(String, index=True, nullable=False, unique=True)

    two_fa_secret = Column(String)

    roll = Column(SmallInteger, nullable=True)

    group_id = Column(Integer, ForeignKey("group.id", ondelete="cascade"))
    group = relationship("Group", backref="student")

    teacher_group = relationship(
        "TeacherGroupCourseAssociation", back_populates="teacher"
    )
    teacher_department_id = Column(
        ForeignKey("department.id", ondelete="SET NULL"), nullable=True
    )
    teacher_department = relationship("Department", backref="teachers")

    dob = Column(Date, nullable=False)
    address = Column(String(length=128), nullable=False)
    contact_number = Column(String(length=32), index=True, nullable=False)

    hashed_password = Column(String, nullable=False)
    is_active = Column(Boolean(), default=False)
    user_type = Column(
        SmallInteger,
        default=settings.UserType.STUDENT.value,
        nullable=False,
        index=True,
    )

    join_year = Column(SmallInteger)

    @hybrid_property
    def is_superuser(self):
        if self.user_type == settings.UserType.SUPERADMIN.value:
            return True
        else:
            return False

    __tablename__ = "user"