jik92/sqladmin-skills
Overview
This skill builds and maintains SQLAdmin admin interfaces for SQLAlchemy models in FastAPI or Starlette apps. It wires sync or async SQLAlchemy engines/sessions, configures ModelView behavior, and adds authentication, role-based permissions, custom templates, and file/image upload integrations. Use it to quickly expose a polished admin UI and to extend admin features with custom views and actions.
How this skill works
I initialize an Admin instance with your FastAPI/Starlette app and a SQLAlchemy engine or sessionmaker (sync or async). For each model I create a ModelView that configures lists, forms, filters, exports, and relationship fields, then add those views to the Admin instance. Authentication backends, per-view access checks, template overrides, custom BaseView pages, and storage-backed file/image columns are wired through documented hooks and options.
When to use it
- You need an admin dashboard to manage SQLAlchemy models in a FastAPI/Starlette project.
- You want role-based access and per-model or per-action permissions in the admin UI.
- You must run an async SQLAlchemy engine/session (asyncio) with admin views.
- You want to customize list columns, forms, filters, exports, or add custom actions.
- You need file/image upload support integrated into admin forms and listings.
Best practices
- Use explicit ModelView configurations for lists, search, filters, and pagination to avoid leaking sensitive fields.
- Implement AuthenticationBackend with is_accessible/is_visible checks for role enforcement and per-view guards.
- Prefer async sessionmakers and ensure ModelView hooks use async patterns when running an async engine.
- Override only the templates you need and keep a fallback to defaults to reduce maintenance.
- Use storage integrations (e.g., fastapi-storages) for robust file and image handling and avoid storing files directly in the DB.
Example use cases
- Add a single /admin dashboard that exposes Product, User, and Order models with role-based access so only admins can edit users.
- Make SQLAdmin work with an async SQLAlchemy engine and async sessionmaker in an asyncio FastAPI app.
- Customize a ModelView to show specific columns, add filters and a CSV export for reporting.
- Create a custom BaseView page with analytics and add a ModelView action button to trigger batch operations.
- Integrate image upload fields for a Product model using storage-backed ImageType columns.
FAQ
Yes. Initialize with create_async_engine and an async sessionmaker and ensure ModelView hooks use async-compatible code.
How do I restrict access to only admin users?
Implement an AuthenticationBackend and apply role checks inside is_accessible and is_visible on your ModelView classes or centrally on the Admin instance.