I have a queryset foo that contains a couple thousand items. Now I would like to add a field bar to this queryset whose value depends on some logic embedded in a loop. So I want to iterate foo and enrich bar for each item.
# Views.py
def example(request):
[..]
# Create `Bar` field for queryset
foo.annotate(bar='')
# Iterate queryset
for item in foo:
[..] # logic that returns a string
# Populate field 'bar'
item.bar = 'example_string'
However, it already breaks at foo.annotate(bar='') returning
QuerySet.annotate() received non-expression(s): .