tortoise / tortoise/tortoise-orm

Filtering arguments as dictionnary

Open
#403 2 comments 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

Describe the solution you'd like
I'd like to be able to pass a dictionnary to a field argument of the filter method like so :

teams = await Team.filter(name= {
    "icontains": "CON",
    "lt": 6,
    "startswith": "a"
})

Describe alternatives you've considered
Right now, the way to do it is :

teams = await Team.filter(name__icontains='CON', id__lt=6, name__startswith="a")

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 reading the existing filter() API and its double-underscore lookup handling. Compare the requested dictionary form with the current equivalent using name__icontains, id__lt, and name__startswith. Done means the dictionary syntax supports the requested lookups without removing the existing form, with tests covering the examples shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.