Opened 14 years ago

Closed 8 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

Description

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 14 years ago.

Download all attachments as: .zip

Change History (9)

by Johannes Dollinger, 14 years ago

Attachment: 11981.q_filter_exclude.diff added

comment:1 by anonymous, 14 years ago

Has patch: set

comment:2 by anonymous, 14 years ago

Has patch: unset
Version: 1.1SVN

comment:3 by Johannes Dollinger, 14 years ago

Has patch: set

...

comment:4 by Russell Keith-Magee, 14 years ago

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 by Julien Phalip, 13 years ago

Severity: Normal
Type: New feature

comment:6 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:7 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:8 by Anssi Kääriäinen, 8 years ago

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