Postgres allows merging/concatenating two JSONB fields into one. Quoting the relevant Postgres docs:
jsonb || jsonb → jsonb - Concatenates two jsonb values.
As far as I can see, the Django ORM does not provide an operator for this type of concatenation. django.db.models.expressions.Combinable does not have a || operator.
django.contrib.postgres.search.SearchQueryCombinable has a || operator, but this class does not seem to apply here.
How can I merge two JSONFields using Django functions, but without evaluating the queryset?
Since expressions usually are of the mixin class
Combinable, we can use the_combinemethod on anFfield and customize the operator to be||.ExpressionWrapperis necessary because Django cannot infer theoutput_fieldof our customized combination.