[Answer]-'Value' object does not support indexing

1๐Ÿ‘

I think the problem is this line:

result_search_obj+=(Value.objects.filter(attribute_id = attributes[j].id 
    , value = values[j]))

You are creating a tuple and appending it to a list. You are expecting to add the tuple as a tuple, but Python flattens the tuple and adds its elements instead.

So you need to change your line as to create a list and to append it to result_search_obj

result_search_obj+= [ (Value.objects.filter(attribute_id = attributes[j].id 
    , value = values[j])) ]

Sample test

>>> x=[]
>>> x += (1, 2)
>>> x
[1, 2]
>>> x += [(1, 2)]
>>> x
[1, 2, (1, 2)]
>>> x += (1, 2)
>>> x
[1, 2, (1, 2), 1, 2]
>>> 
๐Ÿ‘คRohan

Leave a comment