You might get a better result if you build a mapping (i.e. a dict
) of one of the iterables.
To me it looks like you want all the circle
s that have an id
that matches an id
in boundfield.data
.
You could do something like this:
for circle in boundfield.field.queryset:
if circle.id in boundfield.data:
display_val.append(circle.name)
This would also do an iteration, in the background, over the boundfield.data
object. If you want to improve performance there, you could convert it to a Python data type has a fast look-up time, e.g. a set
:
ids = set(boundfield.data)
for circle in boundfield.field.queryset:
if circle.id in ids:
display_val.append(circle.name)
Or, even better:
ids = set(boundfield.data)
display_val = [circle.name for circle in boundfield.field.queryset if circle in ids]
EDIT: If you like one-liners:
display_val = [circle.name for circle in boundfield.field.queryset if circle in boundfield.data]