#29168: Document how to write a custom lookup where the rhs comes before the lhs
-------------------------------------+-------------------------------------
Reporter: JJ Gutierrez | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 2.0
Severity: Normal | Resolution: invalid
Keywords: lookup | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):
* status: new => closed
* resolution: => invalid
* stage: Accepted => Unreviewed
Comment:
> However the documentation is unclear about how to reference the lhs in
the as_sql method. Users would like to know how to reference the rhs
BEFORE the LIKE and the lhs AFTER the LIKE in the sql query above. The
documentation only shows examples where the lhs comes first and the rhs
last. This would help users create a custom lookup with the sql above.
IMO [https://docs.djangoproject.com/en/dev/howto/custom-lookups/#a-lookup-
example "A lookup example"] makes it really clear, I don't see how we
could make it clearer. You need to swap `lhs` and `rhs`, e.g.:
{{{
class Custom(Lookup):
lookup_name = 'custom'
def as_sql(self, compiler, connection):
lhs, lhs_params = self.process_lhs(compiler, connection)
rhs, rhs_params = self.process_rhs(compiler, connection)
params = rhs_params + lhs_params
return '%s LIKE %s||%%' % (rhs, lhs), params
}}}
Closing as invalid.
--
Ticket URL: <https://code.djangoproject.com/ticket/29168#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.8a9d54adc47ec584c3b9c84e95faeab4%40djangoproject.com.