Opened 12 years ago

Closed 12 years ago

#6261 closed (fixed)

Add support for customized WhereNode's and QUERY_TERMS.

Reported by: jbronn Owned by: Malcolm Tredinnick
Component: Database layer (models, ORM) Version: queryset-refactor
Severity: Keywords: qs-rf where wherenode query terms gis
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In order to get GeoDjango working with the queryset-refactor branch, a few modifications were needed to the Query class. Specifically, the GeoQuery subclass of Query needs to the GeoWhereNode instead of the regular WhereNode for the construction of spatial SQL. Moreover, QUERY_TERMS are still hard-coded in the Query class, which also needs to be extended so that geographic lookup types (e.g., within, intersects) are recognized.

This patch adds the where keyword (which sets a where_class attribute of the Query class) to Query.__init__ as well as a get_terms function, both of which may be used and/or overloaded by subclasses. I'm open to suggestions for improvement.

Attachments (1)

query_wherenode.diff (5.0 KB) - added by jbronn 12 years ago.
Patch adding customization options to the Query class.

Download all attachments as: .zip

Change History (4)

Changed 12 years ago by jbronn

Attachment: query_wherenode.diff added

Patch adding customization options to the Query class.

comment:1 Changed 12 years ago by Malcolm Tredinnick

Triage Stage: UnreviewedAccepted

I've been thinking along the same lines, particularly after discussions with you and Jeremy in Lawrence. I think it's probably worth making the WhereNode a class attribute, rather than something to pass to __init__, since then you set it up once and that's done.

Adding extra lookup terms could be done via an attribute or an __init__ parameter. I want to test that and think about which API works easiest (speed is really important in Query and function calls are more expensive than attribute lookups).

I'm guessing you need the WhereNode subclass so that you can override make_atom()? Jeremy and I talked about adding a hook in there for extra lookup types -- would that make that work a bit easier? You wouldn't have to override make_atom() entirely, but, instead, add a new method that is called when none of the standard lookups are matched in the normal processing path. You'd probably still need to subclass (and no reason not to, I guess), but that would make adding new lookup types work.

I'll try to land something in the next couple of days so that we can all work with the same API. I'm also working on spreading the new Query support throughout the rest of core so the branch will be runnable, which might help you a bit, too. That's the over-Christmas project.

comment:2 Changed 12 years ago by Malcolm Tredinnick

Summary: queryset-refactor: Add support for customized WhereNode's and QUERY_TERMS.Add support for customized WhereNode's and QUERY_TERMS.
Version: other branchqueryset-refactor

comment:3 Changed 12 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

Fixed in [7031].

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