I want to get all duplicates based on a case insensitive field value.
Basically to rewrite this SQL query
SELECT count(*), lower(name)
FROM manufacturer
GROUP BY lower(name)
HAVING count(*) > 1;
with Django ORM. I was hoping something like this would do the trick
from django.db.models import Count
from django.db.models.functions import Lower
from myapp.models import Manufacturer
qs = Manufacturer.objects.annotate(
name_lower=Lower('name'),
cnt=Count('name_lower')
).filter('cnt__gt'=1)
but of course it didn't work.
Any idea how to do this?