Opened 12 years ago

Closed 5 years ago

#11981 closed New feature (wontfix)

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

Reported by: Johannes Dollinger Owned by: nobody
Component: Database layer (models, ORM) Version: dev
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 Johannes Dollinger 12 years ago.

Download all attachments as: .zip

Change History (9)

Changed 12 years ago by Johannes Dollinger

Attachment: 11981.q_filter_exclude.diff added

comment:1 Changed 12 years ago by anonymous

Has patch: set

comment:2 Changed 12 years ago by anonymous

Has patch: unset
Version: 1.1SVN

comment:3 Changed 12 years ago by Johannes Dollinger

Has patch: set


comment:4 Changed 11 years ago by Russell Keith-Magee

Triage Stage: UnreviewedSomeday/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 10 years ago by Julien Phalip

Severity: Normal
Type: New feature

comment:6 Changed 9 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:7 Changed 9 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:8 Changed 5 years ago by Anssi Kääriäinen

Resolution: wontfix
Status: newclosed

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