25 lines
1.2 KiB
Python
25 lines
1.2 KiB
Python
Here's the `user.py` file for the `app/api/v1/models/` directory in the `blog_app_igblf` FastAPI backend:
|
|
|
|
from sqlalchemy import Column, Integer, String, Boolean
|
|
from app.db import Base
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
username = Column(String, unique=True, index=True)
|
|
email = Column(String, unique=True, index=True)
|
|
hashed_password = Column(String)
|
|
is_active = Column(Boolean, default=True)
|
|
is_superuser = Column(Boolean, default=False)
|
|
|
|
def __repr__(self):
|
|
return f"User(id={self.id}, username='{self.username}', email='{self.email}')"
|
|
|
|
This file defines a SQLAlchemy model named `User` that inherits from the `Base` class (which should be defined in `app/db.py`). The `User` model has the following columns:
|
|
|
|
- `is_active`: A boolean indicating whether the user is active or not (default is `True`).
|
|
- `is_superuser`: A boolean indicating whether the user is a superuser or not (default is `False`).
|
|
|
|
|
|
Make sure to import the necessary modules (`sqlalchemy` and `app.db`) at the top of the file. Also, ensure that the `Base` class is properly defined in `app/db.py` and that the SQLite database is correctly configured and initialized in your FastAPI application. |