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?
Asked
Active
Viewed 2.8k times
23

sinθ
- 11,093
- 25
- 85
- 121
-
3possible 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 Answers
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