0
Follow
0
View

Distinct not working in DRF sqlite database

dujingjing2013 注册会员
2023-01-25 18:43

I think it is not possible to use order_by and distinct in since in documentation here it is mentioned for example that .

easytelecom 注册会员
2023-01-25 18:43

I have to mention that backend sqlite doesn't support distinct. Consider changing for postgresql as the most supported for django backends.

First you have to order objects by the field if you want to distinct. I have included you the documentation and example.

django distinct

Try out, by putting one of your model field. ex. "name".

class Patient(generics.ListAPIView):

def list(self, request):
    queryset = Patient.objects.order_by('name_field').distinct('name_field')
    serializer = PatientSerializer(queryset, many=True)
    return Response({'patient': serializer.data})

About the Author

Question Info

Publish Time
2023-01-25 18:43
Update Time
2023-01-25 18:43

Related Question

Unity streamingassets加载的图片为啥特别大

springboot+shiro+jwt兼容前后端分离与不分离

不能得到XGetInputFocus时启动没有窗口管理器

Windows11预览版无法安装更新怎么办

如何在python中转换一个hh:mm:ss到秒没有time_string ?

arduino里头文件

python pyinstaller 打包后运行不能退出

通过docker-compose发送参数在.NET6的appsettings上不起作用

如何在gradle lint报告打印构建警告?

Regular Expression to Pull Information from String in Python