[Django] #29168: Custom lookup documentation is incomplete

14 views
Skip to first unread message

Django

unread,
Feb 27, 2018, 8:25:57 PM2/27/18
to django-...@googlegroups.com
#29168: Custom lookup documentation is incomplete
-------------------------------------+-------------------------------------
Reporter: jjwatt99 | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) |
Severity: Normal | Keywords: lookup
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The page for creating custom field lookups is incomplete. I am referring
to the doc at https://docs.djangoproject.com/en/2.0/howto/custom-lookups/.
The documentation is unclear about how to use the left-hand side value
(lhs) and right-hand side value (rhs) properly. For example, lets say you
have a lookup like
{{{
id__custom='abc123'
}}}
The lhs is the ID field and the rhs is the 'abc123'. I want to create a
query like
{{{
WHERE 'abc123' LIKE id||%
}}}
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29168>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 28, 2018, 7:52:51 AM2/28/18
to django-...@googlegroups.com
#29168: Document how to write a custom lookup where the rhs comes before the lhs
-------------------------------------+-------------------------------------
Reporter: JJ Gutierrez | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: lookup | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

Maybe looking at
[https://github.com/django/django/blob/master/django/db/models/lookups.py
the built in lookups] would offer a hint.

--
Ticket URL: <https://code.djangoproject.com/ticket/29168#comment:1>

Django

unread,
Jun 15, 2018, 2:13:02 PM6/15/18
to django-...@googlegroups.com
#29168: Document how to write a custom lookup where the rhs comes before the lhs
--------------------------------------+------------------------------------

Reporter: JJ Gutierrez | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 2.0

Severity: Normal | Resolution:
Keywords: lookup | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* component: Database layer (models, ORM) => Documentation


--
Ticket URL: <https://code.djangoproject.com/ticket/29168#comment:2>

Django

unread,
Feb 20, 2019, 8:45:11 AM2/20/19
to django-...@googlegroups.com
#29168: Document how to write a custom lookup where the rhs comes before the lhs
--------------------------------------+------------------------------------
Reporter: JJ Gutierrez | Owner: samermi1
Type: Cleanup/optimization | Status: assigned

Component: Documentation | Version: 2.0
Severity: Normal | Resolution:
Keywords: lookup | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by samermi1):

* status: new => assigned
* owner: nobody => samermi1


Comment:

I will try to fix this one

--
Ticket URL: <https://code.djangoproject.com/ticket/29168#comment:3>

Django

unread,
Apr 27, 2021, 3:28:48 PM4/27/21
to django-...@googlegroups.com
#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.

Reply all
Reply to author
Forward
0 new messages