#21757: Allow modifying the SQL generated by lookups -------------------------------------+------------------------------------- Reporter: shmishleniy@… | Owner: nobody Type: | Status: new Cleanup/optimization | Version: master Component: Database layer | Resolution: (models, ORM) | Triage Stage: Accepted Severity: Normal | Needs documentation: 0 Keywords: postgresql like | Patch needs improvement: 0 ilike icontains | UI/UX: 0 Has patch: 0 | Needs tests: 0 | Easy pickings: 0 | -------------------------------------+-------------------------------------
Comment (by akaariai): Custom lookups are now implemented. I believe you can alter the feature to work in the way you wish by doing something like this: {{{ from django.db.models import Lookup, Field class Like(Lookup): lookup_name = 'like' def as_sql(self, qn, connection): lhs, lhs_params = self.process_lhs(qn, connection) rhs, rhs_params = self.process_rhs(qn, connection) return '%s LIKE %s' % (lhs, rhs), lhs_params + rhs_params Field.register_lookup(Like) class ILike(Lookup): lookup_name = 'ilike' def as_sql(self, qn, connection): lhs, lhs_params = self.process_lhs(qn, connection) rhs, rhs_params = self.process_rhs(qn, connection) return '%s ILIKE %s' % (lhs, rhs), lhs_params + rhs_params Field.register_lookup(ILike) }}} I haven't actually tried the lookups mentioned above. Try it yourself, any feedback of the lookup system is very welcome. Assuming the lookups mentioned above implement what is wanted we could just close this ticket. -- Ticket URL: <https://code.djangoproject.com/ticket/21757#comment:6> 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/079.1e8084e9b915dce543788545f5990a19%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.