I am trying to create a custom field that automatically adds COLLATE information to the WHERE part of an SQL query:
class IgnoreDiacriticsField(models.TextField):
def get_prep_lookup(self, lookup_type, value):
if lookup_type == 'exact':
return ' "' + self.get_prep_value(value) + '" COLLATE utf8_general_ci'
when I execute a query like this:
result = ModelClass.objects.filter(field='value')
then nothing is found even if the query (print result.query) is valid and matches multiple lines. Am I doing something wrong?
The reason I add iformation for sorting is because I want to execute queries in these fields and ignore any diacritics.
source
share