-
Notifications
You must be signed in to change notification settings - Fork 96
Closed
piccolo-orm/piccolo_admin
#460Description
I'm currently rewriting the
piccolo agsi newsetup for FastAPI. Do you still need thecreate_tables()orcreate_db_tables()function to run, as well as thecreate_adminfunction?
I've changed a few things:
app = FastAPI(
routes=[
Route("/", HomeEndpoint),
Mount(
"/admin/",
create_admin(
tables=APP_CONFIG.table_classes,
# Required when running under HTTPS:
# allowed_hosts=['my_site.com']
),
),
Mount("/static/", StaticFiles(directory="static")),
],
lifespan=lifespan,
)Becomes (using the FastAPI packages rather than Starlette)
app = FastAPI()
admin = create_admin(tables=APP_CONFIG.table_classes) #! (3)
app.mount("/admin", admin) # (2)
app.mount("/static", StaticFiles(directory="static"), name="static")And piccolo_app.py
from piccolo.conf.apps import AppConfig
from tasks.tables import Task
APP_CONFIG = AppConfig(
app_name="tasks",
table_classes=[Task],
migrations_folder_path=None,
migration_dependencies=[],
commands=[]
)I'm trying to remove anything I feel is unnecessary or using Python "magic" so perhaps I've inadvertently broken something. Running the below code as well as create_admin seems to work, but the piccolo agsi new FastAPI example seems to have no create tables function that I can see.
@asynccontextmanager
async def lifespan(app: FastAPI):
await create_db_tables(Task, if_not_exists=True)
yieldMetadata
Metadata
Assignees
Labels
No labels