-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Form fields pre-population #134
Comments
@simplynail Yes, I like this idea. When we render the table forms, we call an endpoint like {
"name": "",
"rating": 0,
"duration": 0,
} As you say, we could add an option to We could also inspect the Pydantic model, in case it has any defaults already. class MyPydanticModel(BaseModel):
name: str = "Unknown" Choices are a bit trickier. Pydantic allows you to specify choices by using enums (see the docs). We could use these. The only problem is they're not dynamic. There would have to be another argument to |
Great, this looks promising. In relation to the dynamic defaults/choices generation, could that be done similarly to what you described that is being done for table view? |
Custom forms are a great feature and look like a quick way to add some calculations or other custom logic to be run from within the admin.
I've been wondering if there would be a possibility to pre-populate form fields so that the user would not only be able to type into blank fields or use hardcoded selects but rather select from a dropdown that was dyjamically generated i.e. from contents of some table?
I imagine that same way as form currently has handler function to be run on submit, there could be a init function that would set up the form fields ie with initial text or generate options for select field. You could run the piccolo ORM query in that init function and then do some logic that would modify the fields defined earlier as Pydantic model
The text was updated successfully, but these errors were encountered: