Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
25 lines
774 B
Python
25 lines
774 B
Python
from sqlalchemy import Column, ForeignKey, Integer, String, UniqueConstraint
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from models import Base
|
|
|
|
|
|
class Category(Base):
|
|
__tablename__ = "categories"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
name = Column(String(50), unique=True, nullable=False)
|
|
|
|
words = relationship("CategoryWord", back_populates="category")
|
|
|
|
|
|
class CategoryWord(Base):
|
|
__tablename__ = "category_words"
|
|
__table_args__ = (UniqueConstraint("category_id", "word"),)
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
category_id = Column(Integer, ForeignKey("categories.id"), nullable=False)
|
|
word = Column(String(20), nullable=False)
|
|
|
|
category = relationship("Category", back_populates="words")
|