[Fixed]-Djangosum two fields from different tables

1👍

using Coalesce from django.db.models.functions solved my issue

SomeModel.objects.filter(
    some_filters
).annotate(
    var=ExpressionWrapper(
        F('val') + Coalesce(F('table2__val'), 0), output_field=FloatField()
    )
)

Leave a comment