I want to concatenate a string variable with one of my field, but can’t figure out what I’m doing wrong
I tried this, where prefix
is a string and filename_mask
is a field in the table
<code> plots = (
PlotDefinitions.objects.filter(is_active=True)
.annotate(
filename=Concat(Value(prefix), 'filename_mask')
)
.values('name', 'description', 'filename')
)
</code>
<code> plots = (
PlotDefinitions.objects.filter(is_active=True)
.annotate(
filename=Concat(Value(prefix), 'filename_mask')
)
.values('name', 'description', 'filename')
)
</code>
plots = (
PlotDefinitions.objects.filter(is_active=True)
.annotate(
filename=Concat(Value(prefix), 'filename_mask')
)
.values('name', 'description', 'filename')
)
I get the error Expression contains mixed types: CharField, TextField. You must set output_field.
even though I’m concatenating 2 String type.
So I added output_field
<code> plots = (
PlotDefinitions.objects.filter(is_active=True)
.annotate(
filename=Concat(Value(prefix), 'filename_mask', output_field=CharField())
)
.values('name', 'description', 'filename')
)
</code>
<code> plots = (
PlotDefinitions.objects.filter(is_active=True)
.annotate(
filename=Concat(Value(prefix), 'filename_mask', output_field=CharField())
)
.values('name', 'description', 'filename')
)
</code>
plots = (
PlotDefinitions.objects.filter(is_active=True)
.annotate(
filename=Concat(Value(prefix), 'filename_mask', output_field=CharField())
)
.values('name', 'description', 'filename')
)
but this gives me the error "'CharField' object has no attribute 'get_internal_type'"