tortoise / tortoise/tortoise-orm
How can I add a virtual property to Model? and it can be set in controller.
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
I'm using fastapi and Tortoise ORM, I need add an no-database property to a model like this:
class Account(models.Model):
id = fields.IntField(pk=True)
email = fields.CharField(max_length=64)
is_new = 0 # this is the abstract property will be set other value in service.
Account_Pydantic = pydantic_model_creator(Account, name="Account")
but this will not have property is_new in the schema, and when I generate open-api dart codes, it will come errors. Can anyone helps? Thanks a lot.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Account example and the pydantic_model_creator(Account, name="Account") call. Trace how Tortoise ORM builds the Pydantic schema and how its OpenAPI output is consumed by the Dart generator. Done means the non-database is_new property is represented in the generated schema without breaking persisted fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100