-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
33 lines (24 loc) · 1.07 KB
/
models.py
File metadata and controls
33 lines (24 loc) · 1.07 KB
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
from sqlalchemy import Column, Integer, String, Text, ForeignKey, Table
from sqlalchemy.orm import relationship
from database import Base
class Matricula(Base):
__tablename__ = "matriculas"
id = Column(Integer, primary_key=True, index=True)
aluno_id = Column(Integer, ForeignKey("alunos.id"))
curso_id = Column(Integer, ForeignKey("cursos.id"))
aluno = relationship("Aluno", back_populates="matriculas")
curso = relationship("Curso", back_populates="matriculas")
class Aluno(Base):
__tablename__ = "alunos"
id = Column(Integer, primary_key=True, index=True)
nome = Column(String, nullable=False)
email = Column(String, nullable=False)
telefone = Column(String, nullable=False)
matriculas = relationship("Matricula", back_populates="aluno")
class Curso(Base):
__tablename__ = "cursos"
id = Column(Integer, primary_key=True, index=True)
nome = Column(String, nullable=False)
codigo = Column(String, nullable=False, unique=True)
descricao = Column(Text)
matriculas = relationship("Matricula", back_populates="curso")