first commit
This commit is contained in:
37
app/modules/coments/models.py
Normal file
37
app/modules/coments/models.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from sqlalchemy import Column, Integer, String, DateTime, Index, Float, Boolean, Text, ForeignKey, Enum as SQLEnum
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.orm import relationship
|
||||
from database import Base
|
||||
|
||||
import enum
|
||||
|
||||
|
||||
class Coments(Base):
|
||||
__tablename__= "coments"
|
||||
|
||||
id = Column(Integer, primary_key=True, nullable=False)
|
||||
texto = Column(Text, nullable=False)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=True)
|
||||
feed_id= Column( Integer, ForeignKey("feed.id"), nullable=True)
|
||||
|
||||
is_active = Column(Boolean, nullable=False, default=True)
|
||||
|
||||
created_at = Column( DateTime(timezone=True), server_default=func.now(), nullable=False)
|
||||
deactivate_at = Column(DateTime(timezone=True), onupdate=func.now(), nullable=True)
|
||||
|
||||
created_by = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
deactivated_by = Column(Integer, ForeignKey("users.id"), nullable=True)
|
||||
|
||||
#index
|
||||
__table_args__ = (
|
||||
Index('idx_coments_feed', 'feed_id'),
|
||||
Index('idx_coments_user', 'user_id'),
|
||||
Index('idx_coments_created', 'created_at'),
|
||||
Index('idx_coments_active', 'is_active')
|
||||
)
|
||||
|
||||
#Relaciones
|
||||
user = relationship("Users", foreign_keys=[user_id], back_populates="coments")
|
||||
feed = relationship("Feed", foreign_keys=[feed_id])
|
||||
creator = relationship("Users", foreign_keys=[created_by])
|
||||
|
||||
Reference in New Issue
Block a user