I have a subquery which returns an array. I want to perform certain operations to pick one data out of that array. I am not able to figure out how to do it.
query_obj = MySecurity.objects.filter(
valid_data=True
).values(
"id",
"rate",
).annotate(
rating_val=Subquery(
MySecurity.object.order_by("-date_of_credit")
.values("credit_code")
),
)
)
I want to process my rating_val which will be an array. I tried pass the subquery result to a fun like:
annotate(
rating_val=myFun(Subquery(
MySecurity.object.order_by("-date_of_credit")
.values("credit_code")
)),
)
)
The above subquery will populate rating_val with ['AA', 'B(CO)']. I want to process this array and find out the lowest rating based on my hierarchy, which I define in const file (rating_hirarchy=['AA', 'B(CO)', '-BB']). According to rating hirarchy 'AA' is greater than 'B(CO) and B(CO) is greater than '-BB'. So now rating_val should have 'B(CO)' as its value But I am not able to access subquery value.
I also tried passing later part of subquery to model manager but again I am not able to access subquery response.