6

I have the following query

country=employees.objects.filter(manager_id__emp_id=111).values('emp_loc').distinct()

I get Output as <QuerySet [{'emp_loc': 'IND'}, {'emp_loc': 'MLA'}]>

But I need list

['IND','MLA']

How Can I do it?

2 Answers 2

11

Use values_list instead.

country=employees.objects.filter(manager_id__emp_id=111).values_list('emp_loc', flat=True).distinct()
Sign up to request clarification or add additional context in comments.

Comments

0

As an alternative suggestion:

country = [ list(elem) for elem in list(employees.objects.filter(manager_id__emp_id=111).values_list('emp_loc', flat=True).distinct()]

1 Comment

Could you please provide some context as to how your solution works and why it might be better than others?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.