tortoise / tortoise/tortoise-orm

Support Django's `.extra(select={...})` feature

Open
#495 8 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

In Django, I can add related table field into current selected field results like this:

    f1 = "SELECT COUNT(*) FROM app_sale1_pp_by_cat WHERE cat_id = app_GoodsCategory.id"
    objs = GoodsCategory.objects.filter(is_leaf=True) \
                                .extra(select={'company_count':f1})

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 by reviewing how Tortoise ORM builds selected fields and how its query API could represent Django's .extra(select={...}) example. Compare the requested related-table count with existing selection support, then define the supported API and verification cases before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.