我正在使用这库,我的模型如下所示:
class PhoneTest(Model):
data = JSONField()我的JSON看起来如下(在真正的obj中有更多的字段):
{ "deviceStatus":true,"officerCode":123456,"imei":123456789123456 }
例如,我想得到所有officerCodes的列表。我该怎么做?到目前为止,我所做的一切都没有起作用。例如,这并没有:
tests = PhoneTests.objects.all()
tests.distinct('data__mOfficerCode')它给出了以下错误:
NotSupportedError: DISTINCT ON fields is not supported by this database backend但这是因为我使用的是这个新库,而不是本地django mysql后端。什么是可能的解决办法?
我非常感谢你的帮助。
发布于 2018-10-10 07:49:59
您可以使用values_list方法
PhoneTests.objects.all().values_list('data__mOfficerCode').distinct()https://stackoverflow.com/questions/52734985
复制相似问题