python - How to avoid duplicate values while retrieving from database in django -


i need avoid duplicate values while retrieving database in django. having result dictionary list.

 queryset = [{'name':'shankar','age':'24'},{'name':'manoj','age':'26'},   {'name':'shankar','age':'25'}] 

i need display value in dropdown list value shankar , manoj. retrieving value query below

 queryset = books.objects.all() 

now want avoid duplicate value while displaying dropdown list in template page.

thanks in advance.

use

queryset = books.objects.all().distinct('name') 

see docs here:

"..on postgresql only, can pass positional arguments (*fields) in order specify names of fields distinct should apply. translates select distinct on sql query. here’s difference. normal distinct() call, database compares each field in each row when determining rows distinct. distinct() call specified field names, database compare specified field names."


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -