29 lines
1.1 KiB
Python

Here's the `user.py` file for the `app/api/v1/models/` directory of the `blog_app_igblf` FastAPI backend, defining a SQLAlchemy model for the `User` entity:
from sqlalchemy import Column, Integer, String, Boolean
from sqlalchemy.orm import relationship
from app.db.base_class import Base
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
email = Column(String, unique=True, index=True, nullable=False)
username = Column(String, unique=True, index=True, nullable=False)
hashed_password = Column(String, nullable=False)
is_active = Column(Boolean, default=True)
is_superuser = Column(Boolean, default=False)
posts = relationship("Post", back_populates="author")
def __repr__(self):
return f"User(id={self.id}, email='{self.email}', username='{self.username}')"
This file defines a `User` model with the following fields:
- `is_active` (Boolean, default=True)
- `is_superuser` (Boolean, default=False)
The `User` model also has a one-to-many relationship with the `Post` model (not defined here), where each user can have multiple posts.