Базовый класс:
Код: Выделить всё
class Person(db_connection.Base):
Id= Column(Integer, primary_key= True, index= True)
Name= Column(String(25), nullable= False)
Address= Column(String(60))
Phone= Column(String(14))
Email= Column(String(70), nullable= False, unique= True)
Password= Column(String(200), nullable= False)
# this will be the discriminator attribute
User_Type= Column(String(9))
__mapper_args__={
"polymorphic_identity": "person",
"polymorphic_on": User_Type,
}
Код: Выделить всё
# USERS TABLE
class User(Person):
__tablename__= 'users'
Id= Column(Integer, ForeignKey('person.Id'), primary_key= True, index= True, nullable=False)
Has_Resume= Column(Boolean, default= 'False')
Title= Column(String(100))
Languages= Column(String)
__mapper_args__={"polymorphic_identity": "users"}
# EMPLOYEE TABLE
class Employee(Person):
__tablename__= 'employees'
Id= Column(Integer, ForeignKey('person.Id'), primary_key= True, index= True, nullable= False)
Employee_ID= Column(String)
Position= Column(String(70))
Company= Column(Boolean, default= 'False')
__mapper_args__={"polymorphic_identity": "employees"}
Код: Выделить всё
{{user_in.Position}}
Код: Выделить всё
# if email and password is valid return the user
def authenticate_user(username: str, password: str, db: Session):
# check if login type is user
user= db.query(Person).filter(Person.Email == username).first()
if user and user.Activated:
# cehck if user and password match in DB
if pass_settings.verify_pass(password, user.Password):
return user
Подробнее здесь: https://stackoverflow.com/questions/798 ... sub-models
Мобильная версия