tortoise / tortoise/tortoise-orm

How can I add a virtual property to Model? and it can be set in controller.

Open
#1,547 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.