-2

I have the following django filter query:

ids = Worksheet.objects.filter(main=main_rec_id).values_list('id', flat=True)

But it return long values like [5L, 6L] how can I get a list like [5,6] guys? Thanks in advance.

1

2 Answers 2

2

use this

ids = Worksheet.objects.filter(main=main_rec_id).values_list('id', flat=True)
ids = map(lambda x:int(x),ids)

ids will be pure integer LIST

Sign up to request clarification or add additional context in comments.

5 Comments

map(lambda x:int(x),ids)
@Sayse: did my edited answer helped?
It produces the output the op is looking for, but its probably still not necessary. The suggested duplicates already provide an explanation.
when you fetch obj from db, by default id will be Long, there must me explicit type casting necessary. or while defining model class mention id=models.IntegerField(.....) could be the possible solution
this may give you possible ans docs.python.org/library/…. If my post helped you out accept it :)
0

[5L, 6L] has no effect for using as [5, 6], because 5L == 5.

1 Comment

5L is 5 returns False. There may be side effects depending on what the op is doing.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.