Apply Function on List

Viewed 49

I have a view method which returns a queryset of fee records in a paginated table

def fee_all(request):

    fee_list = Fee.objects.all().order_by('code') # query for records
    # How to apply separate function e.g. get_column_result 
    # to and append result on the fee_list?

    p = Paginator(fee_list,10) # paginate query
    page = request.GET.get('page') 
    fees = p.get_page(page) # pagination object instance

    context = { 
       'fee_list': fee_list,
       'fees': fees, 
        }

    return render(request, 'fee-all.html', context)

def get_column_result(fee):
    #do operations
    return column_result

Table Sample that I want to achieve

I want to apply a method/function for each queryset item to do a calculation and display the result as an additional column in the displayed table. Considering trying to use Data frames from Pandas with the apply() or Applying lambda function but conversion from resulting dataframe to queryset is difficult. Any ideas?

1 Answers
Related