Documentation for taking an existing FastAPI project and adding a Piccolo admin to it #794
Replies: 6 comments 5 replies
-
Just a quick update on this one. I realized that I hadn't run the migrations for user and session_auth. So I went ahead and ran those
Then I ran
to create a user for admin Was then able to login with the above user I created |
Beta Was this translation helpful? Give feedback.
-
Running into a different issue now related to the same topic. Hence, re-opening this thread. Have my pydantic schemas in schemas.py as below
Also, created the corresponding model in models.py
Tried to generate the admin for the above model as below in app.py
However, when I run
Am getting the below error
How would I go about adding my existing pydantic model to the admin if I started off with a default FastAPI project? |
Beta Was this translation helpful? Give feedback.
-
So, what would be the Piccolo syntax for associating a Post for the below model class, with User
Am essentially, trying to do the Piccolo equivalent of the below User model class for what I would do in pydantic / SQLalchemy
And additionally, establishing a one-to-many relationship between User and Post The Piccolo version of my source code is here - https://github.com/arunabhdas/unicorn-fullstack/tree/main/unicorn-fullstack-fastapi-piccolo/piccolo The FastAPI / SQLAlchemy is here - https://github.com/arunabhdas/unicorn-fullstack/tree/main/unicorn-fullstack-fastapi/blog Also, is there a way to have users be able to be managed in the Piccolo admin? |
Beta Was this translation helpful? Give feedback.
-
Thanks @dantownsend I added the foreign key to Post as below
And that works in as far as getting the Authors and Posts manageable via admin. However, is there a way to have the Post be linked to the user that one creates with the Also, is there a way to have the users created with |
Beta Was this translation helpful? Give feedback.
-
Thanks @dantownsend When I changed exclude_imported=False in piccolo_app.py, then the
So that works great 🚀 However, I now wanted to have a Project model class that has a many-to-one relationship with BaseUser So I tried what you said and I created a model class called Project which has a foreign key referencing BaseUser
Then I ran
However, when I run
Also, without that migration running, I get the following error when I run
Thanks again for your help. Really appreciate it!! |
Beta Was this translation helpful? Give feedback.
-
Thanks @dantownsend !! That worked 🚀 |
Beta Was this translation helpful? Give feedback.
-
I have an existing blog API written in FastAPI here
https://github.com/arunabhdas/unicorn-fullstack/tree/main/unicorn-fullstack-fastapi/blog
Was trying to find instructions in the docs for steps on converting it into a piccolo project.
I got as far as getting the admin route working
Ran the code in https://github.com/arunabhdas/unicorn-fullstack/tree/main/unicorn-fullstack-fastapi/blog
using the command
and am getting the admin login UI -
However, I'm getting the error
Any help would be appreciated @dantownsend
Beta Was this translation helpful? Give feedback.
All reactions