Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions piccolo/utils/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ def create_pydantic_model(
#######################################################################
# Work out the column type

if isinstance(column, (Decimal, Numeric)):
value_type: t.Type = pydantic.condecimal(
if column._meta.choices:
value_type: t.Type = column._meta.choices
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dantownsend Strings work well. Adding these two lines code becomes compatible with Piccolo Admin (with field propertyTitle).

# pydantic.py line 242
if column._meta.choices:
    params["title"] = column._meta.choices.__name__

In Piccolo Admin change this line to v-bind:type="property.type" and this line to class Gender(str, enum.Enum): and everything work well in admin and openapi docs.

Unfortunately ints doesn't work due to validation error.
error

elif isinstance(column, (Decimal, Numeric)):
value_type = pydantic.condecimal(
max_digits=column.precision, decimal_places=column.scale
)
elif isinstance(column, Varchar):
Expand Down