[Django]-Object is not iterable, but becomes iterable

4👍

carls looks like it should be a list of lists, something like [[(1,), (2,), (3,)], [(1,), (2,)]]

When you do [carlid for carlid in c for c in carls] you are trying to iterate over the last defined value of c which would have been a Crush object from similar_crushes.

When you do for c in carls: you redefine c as the last element in the carls list, which is a list of PKs tuples, which is iterable.

for i in range(100):
   pass
print i
# out : 99

Leave a comment