Skip to content

Does create_pydantic_model use optional fields by design #665

Answered by dantownsend
scott2b asked this question in Q&A
Discussion options

You must be logged in to vote

There's a parameter you can pass to your columns called required. By default it's False. create_pydantic_model uses this to determine if a field is optional or not.

class MyTable(Table):
    name = Varchar(required=True)

MyTableModel = create_pydantic_model(MyTable)

# name is now required:
MyTableModel()
>>> Error! 

It's not documented well - we need to add a section to this page explaining it:

https://piccolo-orm.readthedocs.io/en/latest/piccolo/serialization/index.html#

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@scott2b
Comment options

@dantownsend
Comment options

Answer selected by scott2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants