#27429: had to use QuerySet.extra to do WHERE LIKE with arbitrary amount / placement of wildcard characters -------------------------------------+------------------------------------- Reporter: Lance Robertson | Owner: nobody Type: New feature | Status: closed Component: Database layer | Version: master (models, ORM) | Severity: Normal | Resolution: duplicate 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: => duplicate * version: 1.10 => master * component: Uncategorized => Database layer (models, ORM) * type: Uncategorized => New feature Comment: It was decided that we were not going to add `like` and `ilike` lookups in #17473. Now that [https://docs.djangoproject.com/en/1.10/howto/custom-lookups/ custom lookups are available] you can define your own `LIKE` implementation as follow: {{{#!python from django.db.models import CharField, Lookup, TextField class LikeLookup(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 CharField.register_lookup(LikeLookup) TextField.register_lookup(LikeLookup) }}} And use like that {{{#!python Pronunciation.objects.filter(code__like='%% - %%__1 - S T __0 D') }}} -- Ticket URL: <https://code.djangoproject.com/ticket/27429#comment:2> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.114d2cb5a26b532627014847800648de%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.