How to filter objects by ignoring upper and lower case letter django

12,394
Blog.objects.get(name__iexact=receiver_company_name)

you can use iexact which takes all the arguments ignoring upper and lower case

or you can use

Entry.objects.filter(name__istartswith=receiver_company_name)
Share:
12,394

Related videos on Youtube

Baktiyar Bekbergen
Author by

Baktiyar Bekbergen

Senior software engineer Python (Django), Scala developer

Updated on June 19, 2022

Comments

  • Baktiyar Bekbergen
    Baktiyar Bekbergen almost 2 years

    recently I started learning django and I have several questions. And one of them has relationship with __icontains.

    Company.objects.filter(name__icontains=receiver_company_name)

    And let's assume that I have one company which called for example Dota-2, and when I search in my db this company by typing "D", it's return for me Dota-2. And my question will be about, if my company "Dota-2" it's saved in db like this "Dota-2", and when I trying to search like this lowercase "d", it's return me empty array. How to make name_icontains search by ignoring lower and uppercase letter?

    • itzMEonTV
      itzMEonTV almost 7 years
      name__icontains is case insensitive while name__contains is case sensitive
  • Baktiyar Bekbergen
    Baktiyar Bekbergen almost 7 years
    I know about icontains work correctly, but how to make it work with russian letters?
  • Exprator
    Exprator almost 7 years
    if your database is having russian letter then simply pass russian letter in incontains too, it will works as intended
  • Save
    Save over 2 years
    istartswith is used to query for fields that starts with the word.