30 lines
1.7 KiB
Python
30 lines
1.7 KiB
Python
Here's the `user.py` file for the `app/api/v1/models/` directory, defining a SQLAlchemy model for the User entity in the `blog_app_svkgt` FastAPI backend:
|
|
|
|
|
|
from sqlalchemy import Column, Integer, String, Boolean
|
|
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)
|
|
hashed_password = Column(String, nullable=False)
|
|
is_active = Column(Boolean, default=True)
|
|
is_superuser = Column(Boolean, default=False)
|
|
full_name = Column(String, index=True)
|
|
|
|
def __repr__(self):
|
|
return f"User(id={self.id}, email={self.email}, full_name={self.full_name})"
|
|
|
|
Explanation:
|
|
|
|
3. The model has the following columns:
|
|
- `id`: An integer primary key column for uniquely identifying each user.
|
|
- `email`: A string column for storing the user's email address. It is set as unique and indexed for efficient lookups.
|
|
- `hashed_password`: A string column for storing the hashed password of the user.
|
|
- `is_active`: A boolean column indicating whether the user account is active or not. By default, it is set to `True`.
|
|
- `is_superuser`: A boolean column indicating whether the user has superuser privileges or not. By default, it is set to `False`.
|
|
- `full_name`: A string column for storing the user's full name. It is indexed for efficient lookups.
|
|
|
|
Note: This model assumes that you have a `Base` class defined in `app.db.base_class` module, which is typically created using the SQLAlchemy declarative base. You may need to adjust the import statement and the `Base` class according to your project's structure and database configuration. |