Documentation Index
Fetch the complete documentation index at: https://docs.bhuwanpandey.com.np/llms.txt
Use this file to discover all available pages before exploring further.
This guide will help you quickly setup admin dashboard using Fastdaisy-Admin.
If you haven’t already installed Fastdaisy-Admin, follow the installation instructions.
Creating a sqlalchemy model
import contextlib
from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy.orm import declarative_base
Base = declarative_base()
engine = create_engine(
"sqlite:///example.db",
connect_args={"check_same_thread": False},
)
class Book(Base):
__tablename__ = "books"
id = Column(Integer, primary_key=True)
name = Column(String)
@contextlib.asynccontextmanager
async def lifespan(app):
Base.metadata.create_all(engine) # create teables
yield
Fastdaisy-Admin with Starlette
from starlette.applications import Starlette
from fastdaisy_admin import Admin, ModelView
app = Starlette(lifespan=lifespan)
secret_key = "secret_key"
admin = Admin(app, secret_key, engine)
class BookAdmin(ModelView):
model = Book
column_list = [Book.id, Book.name]
admin.add_view(BookAdmin)
OR: Fastdaisy-Admin with FastAPI
from fastapi import FastAPI
from fastdaisy_admin import Admin, ModelView
app = FastAPI(lifespan=lifespan)
secret_key = "secret_key"
admin = Admin(app, secret_key, engine)
class BookAdmin(ModelView):
model = Book
column_list = ['id', Book.name]
admin.add_view(BookAdmin)
and run the server using fastapi dev or uvicorn app:app --reload, which will serve you at http://127.0.0.1:8000/admin.