Opened 7 years ago

Closed 8 months ago

#11981 closed New feature (wontfix)

Add custom Q-object (add_to_query) support to QuerySet.filter() and QuerySet.exclude()

Reported by: emulbreh Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: complex_filter, add_to_query
Cc: Triage Stage: Someday/Maybe
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


It would be nice if custom Q-objects could be transparently used in filter() and exclude() calls (if they provide an __invert__() method).

The following code illustrates the desired behaviour:

class QuerySet(models.query.QuerySet):
    def filter(self, *args, **kwargs):
        if not kwargs and len(args) == 1 and hasattr(args[0], 'add_to_query'):
            return self.complex_filter(args[0])
        return super(QuerySet, self).filter(*args, **kwargs)

    def exclude(self, *args, **kwargs):
        if not kwargs and len(args) == 1:
            return self.complex_filter(~args[0])
        return super(QuerySet, self).exclude(*args, **kwargs)

Attachments (1)

11981.q_filter_exclude.diff (1.9 KB) - added by emulbreh 7 years ago.

Download all attachments as: .zip

Change History (9)

Changed 7 years ago by emulbreh

comment:1 Changed 7 years ago by anonymous

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 7 years ago by anonymous

  • Has patch unset
  • Version changed from 1.1 to SVN

comment:3 Changed 7 years ago by emulbreh

  • Has patch set


comment:4 Changed 7 years ago by russellm

  • Triage Stage changed from Unreviewed to Someday/Maybe

In order to do this, we would need to formalize the interface that Q objects expose. I'm not sure we're in a position to do that at the moment. Long term, it's certainly a desirable goal, though.

comment:5 Changed 5 years ago by julien

  • Severity set to Normal
  • Type set to New feature

comment:6 Changed 5 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:7 Changed 5 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:8 Changed 8 months ago by akaariai

  • Resolution set to wontfix
  • Status changed from new to closed

We will add expressions support instead. This should allow users to do what is wanted in this ticket.

Note: See TracTickets for help on using tickets.
Back to Top