17 lines
603 B
Python
17 lines
603 B
Python
from typing import Optional
|
|
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)
|
|
|
|
author = relationship('Users', back_populates='posts')
|
|
|
|
def __repr__(self):
|
|
return f'Post(id={self.id}, title={self.title}, content={self.content[:20]}...)' |