#30074: Cannot Un-escape LIKE wildcards without .extra()
-------------------------------------+-------------------------------------
Reporter: dwdresser | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: QuerySet.extra | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* status: new => closed
* resolution: => invalid
Comment:
Hello there,
Unfortunately the API you are suggesting through `filter(escape=True)` is
backward incompatible. I'm also not convinced this use case is common
enough to warrant the inclusion of such option given this can easily be
implemented by registering [https://docs.djangoproject.com/en/2.1/howto
/custom-lookups/ a custom lookup].
e.g.
{{{#!python
from django.db import models
class Like(models.Lookup):
lookup_name = 'like'
def as_sql(self, compiler, connection):
lhs, lhs_params = self.process_lhs(compiler, connection)
rhs, rhs_params = self.process_rhs(compiler, connection)
params = lhs_params + rhs_params
return '%s LIKE %s' % (lhs, rhs), params
models.CharField.register_lookup(Like)
models.TextField.register_lookup(Like)
Foo.objects.filter(bar__like='unescaped % or _')
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30074#comment:1>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.2dd1f58bd3b2117bbb086b1e705f5c21%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.