在django中DISTINCT ON [英] DISTINCT ON in django

查看:772
本文介绍了在django中DISTINCT ON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何执行以下查询:

OrderNotes.objects.filter(item=item).distinct('shared_note')

基本上,我需要得到所有的 OrderNotes 项目,在 shared_note 上不同。当我尝试这样做我得到:

Basically, I need to get all OrderNotes items, distinct on shared_note. When I try and do this I get:

    raise NotImplementedError('DISTINCT ON fields is not supported by this database backend')

NotImplementedError: DISTINCT ON fields is not supported by this database backend

我是使用mysql并不能在这里更改db。 django中的解决方法是什么?

I am using mysql and cannot change the db here. What would be the workaround in django?

推荐答案

OrderNotes.objects.filter(item=item).values_list('shared_note', flat=True).distinct()

这篇关于在django中DISTINCT ON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆