4👍
You can use dict
unpacking with the **
operator to provide dynamic keyword arguments to any function and you should probably reassign the query:
query = query.annotate(**{'day_' + i + '_usage': "doesn't matter"})
1👍
When you do an annotation or other operation on a queryset, it returns a new instance of the queryset. It doesn’t modify the previous queryset.
So change your statement in the loop to
query = query.annotate(...)
- [Django]-Populate json to html with django template
- [Django]-Django All-Auth django.contrib.auth.backends.ModelBackend invalid syntax
- [Django]-Crispy Forms Initial data
Source:stackexchange.com