создал новые таблицы
This commit is contained in:
parent
afb348167d
commit
0a4f3920a9
@ -1,4 +1,4 @@
|
|||||||
from sqlalchemy import Column, Integer, VARCHAR, String, ForeignKey, Date, Boolean
|
from sqlalchemy import Column, Integer, ForeignKey, Date, Boolean
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
|||||||
@ -18,3 +18,4 @@ class Course(Base):
|
|||||||
owner_user = relationship('User', back_populates='owned_courses')
|
owner_user = relationship('User', back_populates='owned_courses')
|
||||||
|
|
||||||
students = relationship('CourseStudent', back_populates='course')
|
students = relationship('CourseStudent', back_populates='course')
|
||||||
|
notifications = relationship('Notification', back_populates='course')
|
||||||
|
|||||||
14
API/app/infrastructure/database/models/notification_types.py
Normal file
14
API/app/infrastructure/database/models/notification_types.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from sqlalchemy import Column, Integer, VARCHAR, String
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from app.infrastructure.database.models import Base
|
||||||
|
|
||||||
|
|
||||||
|
class NotificationType(Base):
|
||||||
|
__tablename__ = 'notification_types'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(100), nullable=False)
|
||||||
|
description = Column(String, nullable=False)
|
||||||
|
|
||||||
|
notifications = relationship('Notification', back_populates='type')
|
||||||
22
API/app/infrastructure/database/models/notifications.py
Normal file
22
API/app/infrastructure/database/models/notifications.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from sqlalchemy import Column, Integer, Boolean, String, DateTime, ForeignKey
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from app.infrastructure.database.models import Base
|
||||||
|
|
||||||
|
|
||||||
|
class Notification(Base):
|
||||||
|
__tablename__ = 'notifications'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
text = Column(String, nullable=False)
|
||||||
|
datetime_notification = Column(DateTime, nullable=False, default=func.utcnow)
|
||||||
|
is_read = Column(Boolean, nullable=False, default=False)
|
||||||
|
|
||||||
|
user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
|
||||||
|
type_id = Column(Integer, ForeignKey('notification_types.id'), nullable=False)
|
||||||
|
course_id = Column(Integer, ForeignKey('courses.id'))
|
||||||
|
|
||||||
|
user = relationship('User', back_populates='notifications')
|
||||||
|
type = relationship('NotificationType', back_populates='notifications')
|
||||||
|
course = relationship('Course', back_populates='notifications')
|
||||||
@ -35,6 +35,7 @@ class User(Base):
|
|||||||
appeals = relationship('Appeal', back_populates='user')
|
appeals = relationship('Appeal', back_populates='user')
|
||||||
owned_courses = relationship('Course', back_populates='owned_courses')
|
owned_courses = relationship('Course', back_populates='owned_courses')
|
||||||
enrolled_courses = relationship('CourseStudent', back_populates='user')
|
enrolled_courses = relationship('CourseStudent', back_populates='user')
|
||||||
|
notifications = relationship('Notification', back_populates='user')
|
||||||
|
|
||||||
def check_password(self, password):
|
def check_password(self, password):
|
||||||
return check_password_hash(self.password, password)
|
return check_password_hash(self.password, password)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user