18 lines
664 B
Python
18 lines
664 B
Python
from sqlalchemy import Column, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import relationship
|
|
from app.api.db.database import Base
|
|
|
|
class Posts(Base):
|
|
__tablename__ = 'posts'
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
title = Column(String, nullable=False)
|
|
content = Column(Text, nullable=False)
|
|
user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
|
|
category_id = Column(Integer, ForeignKey('categories.id'), nullable=False)
|
|
|
|
user = relationship('User', back_populates='posts')
|
|
category = relationship('Category', back_populates='posts')
|
|
|
|
def __repr__(self):
|
|
return f'<Post {self.title}>' |