Changes between Version 1 and Version 2 of Ticket #36261, comment 1


Ignore:
Timestamp:
Mar 16, 2025, 8:54:03 PM (13 days ago)
Author:
Simon Charette

Legend:

Unmodified
Added
Removed
Modified
  • TabularUnified Ticket #36261, comment 1

    v1 v2  
    1717
    1818Not an expert but I think this might cause more harm than good as it basically ignore the specified collation on the column?
     19
     20For anyone running into this problem you can register field instance lookups to work around the problem
     21
     22{{{#!python
     23from django.db.models.lookups import Contains, IContains
     24
     25class Foo(models.Model):
     26    bar = models.TextField(db_collation="und-u-ks-level2")
     27
     28
     29# See https://docs.djangoproject.com/en/5.1/howto/custom-lookups/#a-lookup-example
     30class NonDetermisticContains(Contains):
     31    def as_postgresql(self, compiler, connection):
     32        lhs, lhs_params = self.process_lhs(compiler, connection)
     33        rhs, rhs_params = self.process_rhs(compiler, connection)
     34        params = lhs_params + rhs_params
     35        return f'{lhs} COLLATE "default"' LIKE {rhs}', params
     36
     37Foo._meta.get_field("bar").register_lookup(NonDetermisticContains)
     38}}}
Back to Top