Search code examples
djangodjango-modelsdjango-rest-frameworkdjango-querysetquery-expressions

In Django, is there a way to set field values with a query expression on objects returned from a queryset?


I have a proxy model which has to have some calculated (with query expressions) read-only fields. Annotating won't do, because I will later need to have field metadata to do filtering in my views.

So, is there a way to call a SQL function to get the value?

I am looking for something like a QuerySet.annotate for fields, a Transform or a custom field that would do this.


Solution

  • I found a way to do this by using the Col Expression and a custom field.