Opened 16 years ago
Closed 10 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)
Change History (9)
by , 16 years ago
| Attachment: | 11981.q_filter_exclude.diff added |
|---|
comment:1 by , 16 years ago
| Has patch: | set |
|---|
comment:2 by , 16 years ago
| Has patch: | unset |
|---|---|
| Version: | 1.1 → SVN |
comment:3 by , 16 years ago
| Has patch: | set |
|---|
comment:4 by , 16 years ago
| Triage Stage: | Unreviewed → 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 by , 15 years ago
| Severity: | → Normal |
|---|---|
| Type: | → New feature |
comment:8 by , 10 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
We will add expressions support instead. This should allow users to do what is wanted in this ticket.
...