Consider a table called DataTable
. It has two fields: A
and B
.
I want to return all rows from this table, and annotating a field called C
which is a concatenation of A
and B
fields.
Here is what I have tried:
from django.db.models import CharField, Value
from .models import DataTable
def Test(request):
query = DataTable.objects.all().annotate(C=Value('A' + '-' + 'B',
output_field=CharField()))
# the rest of the function...
The problem here is that C
is literally just the string literal "A - B" for every returned row.
I want to concatenate the values of A
and B
fields.
F()
? F('A') – Venireman