Code

Opened 6 years ago

Closed 6 years ago

#6261 closed (fixed)

Add support for customized WhereNode's and QUERY_TERMS.

Reported by: jbronn Owned by: mtredinnick
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: UI/UX:

Description

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 6 years ago.
Patch adding customization options to the Query class.

Download all attachments as: .zip

Change History (4)

Changed 6 years ago by jbronn

Patch adding customization options to the Query class.

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 6 years ago by mtredinnick

  • Summary changed from queryset-refactor: Add support for customized WhereNode's and QUERY_TERMS. to Add support for customized WhereNode's and QUERY_TERMS.
  • Version changed from other branch to queryset-refactor

comment:3 Changed 6 years ago by mtredinnick

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

Fixed in [7031].

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.