Skip to content
Advertisement

Is it possible to add values to context into a for loop?

I have a for loop to iterate a list. In every iteration i have a different value, and i want to add this value to my context. I’m trying using context.update, but every time this returns an empty context.

JavaScript

cCard returns correct data. The only thing I need is to store what come from cCard to context[‘card_list’], but evert attempt i made, was an empty result.

Advertisement

Answer

Please don’t filter that way. This will produce n+1 queries, one for each Column. You can retrieve the last of Cards with:

JavaScript

You can use two consecutive underscores (__) to look “through” relations like a ForeignKey, ManyToManyField, etc.

Advertisement