mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-27 00:01:03 -05:00
* ✨ Implement support for Pydantic's ORM mode * 🏗️ Re-structure/augment SQL tutorial source using ORM mode * 📝 Update SQL docs with SQLAlchemy, ORM mode, relationships * 🔥 Remove unused util in tutorial * 📝 Add tutorials for simple dict bodies and responses * 🔥 Remove old SQL tutorial * ✅ Add/update tests for SQL tutorial * ✅ Add tests for simple dicts (body and response) * 🐛 Fix cloning field from original field
27 lines
734 B
Python
27 lines
734 B
Python
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from .database import Base
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
email = Column(String, unique=True, index=True)
|
|
hashed_password = Column(String)
|
|
is_active = Column(Boolean, default=True)
|
|
|
|
items = relationship("Item", back_populates="owner")
|
|
|
|
|
|
class Item(Base):
|
|
__tablename__ = "items"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
title = Column(String, index=True)
|
|
description = Column(String, index=True)
|
|
owner_id = Column(Integer, ForeignKey("users.id"))
|
|
|
|
owner = relationship("User", back_populates="items")
|