You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pydantic_model_creator lets you pass the exclude_readonly argument, however, the documentation does not specify what exactly is going to be excluded. Looks like the primary key won't be included but what else?
Please have a look at the following example
from tortoise import fields
from tortoise.contrib.pydantic import pydantic_model_creator
from tortoise.models import Model
class People(Model):
id = fields.IntField(pk=True)
created_at = fields.DatetimeField(auto_now_add=True)
modified_at = fields.DatetimeField(auto_now=True)
first_name = fields.CharField(max_length=50)
last_name = fields.CharField(max_length=50)
PersonIn = pydantic_model_creator(People, name="PersonIn", exclude_readonly=True)
print(list(PersonIn.model_fields))
It prints ['first_name', 'last_name'], so created_at and modified_at aren't included either.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!
pydantic_model_creator
lets you pass theexclude_readonly
argument, however, the documentation does not specify what exactly is going to be excluded. Looks like the primary key won't be included but what else?Please have a look at the following example
It prints
['first_name', 'last_name']
, socreated_at
andmodified_at
aren't included either.Beta Was this translation helpful? Give feedback.
All reactions