'Django ORM filter by lowercase only

How do I use Django ORM to filter objects that only show the lowercase only? For example in my case, I want to update all emails that has "non-lowercase" objects to "lowercase".

from django.db.models.functions import Lower

User.objects.exclude(email__islower=True).update(email=Lower("email"))
                             /|\
                              |


Solution 1:[1]

Currently, I'm using __regex expression to solve this,

User.objects.exclude(email__regex="^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9-]+)*$").update(email=Lower("email"))

with this email patterns: https://www.abstractapi.com/tools/email-regex-guide

But, hopefully there would have any better solutions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 binpy