16 lines
528 B
Python
16 lines
528 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)
|
|
content = Column(Text)
|
|
user_id = Column(Integer, ForeignKey('users.id'))
|
|
|
|
user = relationship('User', back_populates='posts')
|
|
|
|
def __repr__(self):
|
|
return f'Post(id={self.id}, title="{self.title}", content="{self.content[:20]}...")' |