Coverage for docs_src/sql_databases/sql_app_py310/models.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from sqlalchemy import Boolean, Column, ForeignKey, Integer, String 1abc

2from sqlalchemy.orm import relationship 1abc

3 

4from .database import Base 1abc

5 

6 

7class User(Base): 1abc

8 __tablename__ = "users" 1abc

9 

10 id = Column(Integer, primary_key=True) 1abc

11 email = Column(String, unique=True, index=True) 1abc

12 hashed_password = Column(String) 1abc

13 is_active = Column(Boolean, default=True) 1abc

14 

15 items = relationship("Item", back_populates="owner") 1abc

16 

17 

18class Item(Base): 1abc

19 __tablename__ = "items" 1abc

20 

21 id = Column(Integer, primary_key=True) 1abc

22 title = Column(String, index=True) 1abc

23 description = Column(String, index=True) 1abc

24 owner_id = Column(Integer, ForeignKey("users.id")) 1abc

25 

26 owner = relationship("User", back_populates="items") 1abc