Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Limit 1 after filter in django

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'}]>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use .distinct()

SystemsV2.objects.filter(Q(sysname = 'DC_BW_SBX_S4H') | Q(sysname='DC_BW_DEV_S4H')).values('sysname')\
    .order_by('sysname').distinct()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading