-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.

vellattukudy
  • 789
  • 2
  • 11
  • 25
  • Some explanation here: [django integer field returning long](http://stackoverflow.com/questions/7733002/django-integerfield-returning-long) – Moses Koledoye May 25 '16 at 09:26

2 Answers2

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

Arun G
  • 1,678
  • 15
  • 17
  • map(lambda x:int(x),ids) – Arun G May 25 '16 at 09:46
  • @Sayse: did my edited answer helped? – Arun G May 25 '16 at 09:49
  • It produces the output the op is looking for, but its probably still not necessary. The suggested duplicates already provide an explanation. – Sayse May 25 '16 at 09:50
  • 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 – Arun G May 25 '16 at 09:59
  • this may give you possible ans http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex. If my post helped you out accept it :) – Arun G May 25 '16 at 10:03
0

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

Yuan Wang
  • 145
  • 4
  • `5L is 5` returns False. There *may* be side effects depending on what the op is doing. – Sayse May 25 '16 at 09:30