title: Django: Annotate sum on variable number of columns
body: <p>So I've read the annotate columns, and utilizing the F() functions, and I saw <a href="https://stackoverflow.com/questions/43323724/django-orm-sum-of-multiple-columns/43323971">this post</a> on how to sum multiple columns. However, I'm working with an EAV style DB, so I'm given a variable list of columns. Consider the example:</p>
  
  <pre><code>class TestModel(models.Model):
      column_a = models.FloatField()
      column_b = models.FloatField()
      column_c = models.FloatField()
      column_d = models.FloatField()
  </code></pre>
  
  <p><strong>ATTEMPT 1:</strong></p>
  
  <pre><code>columns = {'column_a', 'column_c', 'column_d'}
  queryset = DummyModel.objects.annotate(total=Sum([F(column_name) for column_name in columns]))
  </code></pre>
  
  <p>However, a <code>print(queryset.query)</code> yields the error <code>django.core.exceptions.FieldError: Cannot resolve expression type, unknown output_field</code></p>
  
  <p><strong>ATTEMPT 2:</strong></p>
  
  <pre><code>queryset = DummyModel.objects.annotate(total=ExpressionWrapper(Sum([F(column_name) for column_name in columns]), output_field=FloatField())) 
  </code></pre>
  
  <p>This does not yield a compilation error, but the SQL query yields:</p>
  
  <pre><code>SELECT "test_model"."column_a", "test_model"."column_c", "test_model"."column_d", SUM([]) AS "total" FROM "test_model"
  </code></pre>
  
  <p>Which is empty. Does anyone have any idea of how to solve this? Any help is greatly appreciated!</p>