-
Notifications
You must be signed in to change notification settings - Fork 39
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
Support Enum types within Forms #434
Conversation
So PoC form: from enum import Enum
from pydantic import BaseModel
from starlette.requests import Request
from piccolo_admin.endpoints import FormConfig
class Test(Enum):
ONE = "ONE"
TWO = "TWO"
THREE = "THREE"
class CalculatorModel(BaseModel):
number_1: int
number_2: int
enum: Test
def calculator(request: Request, data: CalculatorModel):
"""
A very simple example of a form which adds numbers together.
"""
return f"The answer is {data.number_1 + data.number_2} with enum {data.enum}."
FORM = FormConfig(
name="Calculator",
pydantic_model=CalculatorModel,
endpoint=calculator,
description=("Adds two numbers together."),
) |
@Skelmis There was a PR to enable Python Enums in custom forms. I used Piccolo |
What changes are required within the API? Possibly I've overlooked something but I don't feel like it may require changes |
@Skelmis |
Interesting, I wonder then how $refs are currently propgrating then given this draft is essentially working. I might take a poke later |
Ah my mistake, sorry. I forgot that custom forms using Pydantic |
@Skelmis Thanks for taking a look at this, looks like some great progress! I don't mind us changing |
I actually prefer how it currently works because then you get a display value and the actual value versus $ref which at face value is just the raw value |
I'm currently getting the following error, could either of you give me a hand resolving it?
|
<div | ||
v-if="Object.keys(property).includes('$ref')" | ||
> | ||
<label>{{ schema["$defs"][Number(property['$ref']?.split(/[//]+/).pop())].title }}</label> |
Check warning
Code scanning / CodeQL
Duplicate character in character class Warning
repeated in the same character class
Closing in favor of #436 |
My attempt at supporting Enum's within Forms.
Note this is my first time working with Vue and as such I'm trying to figure things out and just get them working. I'd love feedback and improvements.
#430