tortoise / tortoise/tortoise-orm

ReverseRelation should also provide exclude()

Open
#455 1 comment 1 reaction 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

Is your feature request related to a problem? Please describe.
As ReverseRelation provides filter() method, it should also provide exclude() for convenience.

Describe the solution you'd like
Here is a quick patch:

--- tortoise/fields/relational.py	2020-04-22 16:00:54.000000000 +0200
+++ tortoise/fields/relational.py	2020-07-07 22:12:28.000000000 +0200
@@ -124,6 +124,12 @@
         """
         return self._query.filter(*args, **kwargs)
 
+    def exclude(self, *args: "Q", **kwargs: Any) -> "QuerySet[MODEL]":
+        """
+        Returns a QuerySet with related elements excluded by args/kwargs.
+        """
+        return self._query.exclude(*args, **kwargs)
+
     def all(self) -> "QuerySet[MODEL]":
         """
         Returns a QuerySet with all related elements.

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 in tortoise/fields/relational.py beside the existing ReverseRelation filter() and all() methods, then inspect the underlying QuerySet exclude() entry point. The work is done when ReverseRelation exposes exclude() with the same arguments and forwards them to the related query, matching the supplied patch.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
database
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.