2

Is it possible to get Author.objects.filter(surname__istartswith='Z') return results that also start with 'Ž', 'Ź' etc.?

The only solution that comes into my mind is to flatten surname with unicode transliteration and save it as surname_flat in db. Then Author.objects.filter(surname_flat__istartswith='Z') would work, but it requires database migration.

I'm using postgres.

1
  • Your approach is the one that I would use. Nov 26, 2012 at 11:54

1 Answer 1

1

The django-unaccent library has been written to provide the functionality you require.

By doing this however you are making your solution database-dependent, which may be an issue if you decide to move database engines in future.

Your solution to add an additional calculated column is the one that I would use, as this keeps your code db-independent. You can also index your column more effectively. Because the django-unaccent library uses a database-function-based search, it will do a column scan of your data every time you use it.

1
  • Thank you, this is robust solution, however database migration is less pain in my case, I will use calculated column approach.
    – zahory
    Nov 26, 2012 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.