django-orm 不区分大小写的分组依据
django-orm case-insensitive group by
我正在尝试以不区分大小写的方式用它们的计数来注释我的数据。我发现了这个类似的问题:django-orm case-insensitive order by 并尝试了这个:
from django.db.models.functions import Lower
Posts.objects.filter(published=True).values('author').annotate(Lower('author'))
然而 returns:
AttributeError: 'Lower' object has no attribute 'split'
我也试过这个:
Posts.objects.filter(published=True).values('author').annotate(c=Count(Lower('author')))
没有效果,结果区分大小写。
尝试在 Count
:
之前使用 Lower
注释您的数据
Posts.objects.filter(published=True).annotate(lauthor=Lower('author')).values('lauthor').annotate(c=Count('id'))
我正在尝试以不区分大小写的方式用它们的计数来注释我的数据。我发现了这个类似的问题:django-orm case-insensitive order by 并尝试了这个:
from django.db.models.functions import Lower
Posts.objects.filter(published=True).values('author').annotate(Lower('author'))
然而 returns:
AttributeError: 'Lower' object has no attribute 'split'
我也试过这个:
Posts.objects.filter(published=True).values('author').annotate(c=Count(Lower('author')))
没有效果,结果区分大小写。
尝试在 Count
:
Lower
注释您的数据
Posts.objects.filter(published=True).annotate(lauthor=Lower('author')).values('lauthor').annotate(c=Count('id'))