SystemsV2.objects.filter(Q(sysname = 'DC_BW_SBX_S4H') | Q(sysname='DC_BW_DEV_S4H')).values('sysname')
Executing the above command gives this output,
<QuerySet [{'sysname': 'DC_BW_SBX_S4H'}, {'sysname': 'DC_BW_SBX_S4H'}, {'sysname': 'DC_BW_DEV_S4H'}]>
How can we make it so that only one of each exists in the result. For example,
<QuerySet [{'sysname': 'DC_BW_SBX_S4H'}, {'sysname': 'DC_BW_DEV_S4H'}]>
CodePudding user response:
Use .distinct()
SystemsV2.objects.filter(Q(sysname = 'DC_BW_SBX_S4H') | Q(sysname='DC_BW_DEV_S4H')).values('sysname')\
.order_by('sysname').distinct()