I have a simple model like this:
class Payments(models.Model):
dt=models.DateField()
payer=models.IntegerField(default=0)
If a member pays for himself, payer=0. But sometimes his support group (there are many groups) can pay for him/her and when that happens, the payer holds the ID of the support group. I didn't want to implement a relationship here.
Now I want to list payments made but when payer>0, to get name of the subgroup that actually paid for the member.
data=Payments.objects.filter(**build_filters['filters']).annotate(support_group_name=Case(When(payer__gt=0, then=Value('support group name goes here'), default=Value(''), output_field=CharField())).values('support_group_name','id','dt')
I already have a function that use from various locations which returns name of a support group provided with id. I tried:
data=Payments.objects.filter(**build_filters['filters']).annotate(support_group_name=Case(When(payer__gt=0, then=Value(support_name(payer)), default=Value(''), output_field=CharField())).values('support_group_name','id','dt')
But I get payer is undefined. Any idea what I can do about this?