为了在 django 中使用 .distinct()
了解我们使用 MySQL,是否有替代方法
In [48]: perc = Perception.objects.all()
In [49]: perc
Out[49]: <QuerySet [<Perception: Perception #0000001>, <Perception: Perception #0000002>, <Perception: Perception #0000003>, <Perception: Perception #0000004>]>
In [50]: perc.filter(loan__request__customer=205).distinct('loan__request__cust
...: omer__user__last_name')
Out[50]:
事实上,我在网站 Django MySQL distinct query for getting multiple values 上读到“.distinct([*fields])
仅适用于 PostgresSQL” 。该问题与第 50 行有关,该行未返回任何内容。
问题:当我们使用 MySQL 时,Django 中的 .distinct()
是否有替代方案?
谢谢!
P.S.如果问题不清楚,请告诉我。
最佳答案
你试过吗
Perception.objects.all().values_list('my_field', flat=True).distinct()
我还没有测试过,但请尝试一下并告诉我。
关于python - 将 .distinct() 与 MySQL 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43379328/