Reputation: 151
Hi I have two models named A and B. I want to get the ids from my model B and compare it with the id in model A (Foreign Key relation). I used the following method to get the ids
a = B.objects.filter(b_id=object.id).values_list('id')
But a printed a result of [(82L,), (83L,), (84L,), (85L,)]
instead of [82, 83 ,]
etc.
How can I get a flat list without the appended L
s?
Upvotes: 2
Views: 351
Reputation: 2157
These numbers are long integers. As such, they are returned with an L
suffix. There really is no letter 'L' after the number though. This has been removed in Python 3, since all integers are now treated as long integers. I don't believe what you are seeing is any cause for alarm.
Edit: See why-do-integers-in-database-row-tuple-have-an-l-suffix for more info.
Upvotes: 2
Reputation: 15388
values_list()
by default returns the values grouped into tuples.
If you don't want that, use
values_list('id', flat=True)
Upvotes: 5