尝试:
from django.db.models import CountLiteral.objects.values('name') .annotate(Count('id')) .order_by() .filter(id__count__gt=1)这与使用Django所获得的效果非常接近。问题在于这将返回一个
ValuesQuerySetwith
name和
count。但是,你可以
QuerySet通过将其反馈给另一个查询来使用它来构造一个常规:
dupes = Literal.objects.values('name') .annotate(Count('id')) .order_by() .filter(id__count__gt=1)Literal.objects.filter(name__in=[item['name'] for item in dupes])


