23

I have an member model with contains an email field. I recently realized that if a part of the email is capitalized, it won't show up in Django queries if I try to filter by the email (multiple member objects have the same email, but it may not be capitalized). I could have just made all emails lower-case when entering them into the database, but it's too late for that now (as the website is already launched). So how do I check who has a certain email, without being case sensitive?

sinθ
  • 11,093
  • 25
  • 85
  • 121
  • 3
    possible duplicate of [Django Model - Case-insensitive Query / Filtering](http://stackoverflow.com/questions/11743207/django-model-case-insensitive-query-filtering) – melbic Mar 13 '14 at 07:26

2 Answers2

62

Just use iexact:

User.objects.filter(email__iexact='email@email.com')

Case-insensitive exact match. If the value provided for comparison is None, it will be interpreted as an SQL NULL (see isnull for more details).

gdvalderrama
  • 713
  • 1
  • 17
  • 26
drewman
  • 1,565
  • 11
  • 15
8
Member.objects.filter(email__iexact=email)
bakkal
  • 54,350
  • 12
  • 131
  • 107