3👍
✅
Probably, you’re looking for unpacking. In case when a function expects separate arguments, and you have those arguments in a list or tuple you should use *
to unpack the values as separate. There’s a similar syntax **
for the case with dictionaries.
In you case, try:
my_list = ['month', 'location']
truncate_date = connection.ops.date_trunc_sql('month', 'created')
qs = Order.objects.extra({'month':truncate_date})
report = qs.values(*my_list).annotate(Count('pk'))
3👍
If you have a list of wanted values you can use the *
syntax:
truncate_date = connection.ops.date_trunc_sql('month', 'created')
qs = Order.objects.extra({'month':truncate_date})
value_list = ['month', 'location']
report = qs.values(*value_list).annotate(Count('pk'))
- [Django]-Select a valid choice. That choice is not one of the available choices
- [Django]-Type object is not iterable Django
- [Django]-Issue with returning Cyrillic symbols from MSSQL via unixODBC and FreeTDS
Source:stackexchange.com