Closed zhaowanpeng closed 1 month ago
Not sure what you are trying to do here
There is no param readonly
for model fields
If you want to exclude fields from schema - try using exclude
param
Thank you for your reply. I reviewed the source code again and realized that my understanding was insufficient. Thank you.
It is worth noting that CharField comes with a default_factory by default, whereas IntField does not. This can lead to misunderstandings, causing some to subconsciously assume that CharField and IntField, when having similar parameters, are either both required or both optional.
My code: ` from tortoise import models, fields
class Channel(models.Model): id = fields.IntField(pk=True, readonly=True) create_user_id = fields.IntField(null=True, readonly=True) audit_user_id = fields.IntField(null=True, default=None, readonly=True) `
Usage: ` from tortoise.contrib.pydantic import pydantic_model_creator
schema = pydantic_model_creator(Channel, exclude_readonly=True) `
Error:
Despite exclude_readonly=True, create_user_id and audit_user_id are included in the schema and they are not marked as optional.