title: How can i display a custom method to a model in a template using views(generic)?
body: <p>I have added a custom method to my fee profile model, and i wanted it to calculate for me the fee balance when a fee instance is created. First, before adding the custom method, everything was working out well. I could add a fee profile instance in the django admin without getting errors. Also, i have included a dictionary that stores the fee payment history and am unable to figure out a way to display the fee payment history on a template.I am running django 3.1.4, and using python 3.8.5. Here is my code:</p>
  <p>This is the error i got.</p>
  <blockquote>
  <p>&quot;<strong>str</strong> returned non-string (type Child)</p>
  </blockquote>
  <p>All was working well till i introduced the fee_status() custom method.</p>
  <p>admin.py</p>
  <pre><code>@admin.register(FeeProfile)
  class FeeProfile(admin.ModelAdmin):
      list_display = (
          'child', 'amount_paid', 'date', 'fee_status'
      )
      list_filter = ['date']
      search_fields = ['child']
  </code></pre>
  <p>models.py</p>
  <pre><code>class FeeProfile(models.Model):
      child = models.ForeignKey('bjs_main.Child', on_delete=models.CASCADE)
      parent = models.ForeignKey('bjs_main.Parent', on_delete=models.CASCADE)
      mpesa_code = models.CharField(max_length=10, primary_key=True)
      amount_paid = models.IntegerField(default=0)
      date = models.DateTimeField(auto_now_add=True)
  
      def __str__(self):
          return self.child
  
      def fee_status(self):
          global total_amount_paid
          total_amount_paid += self.amount_paid
          fee_balance = term_fee - total_amount_paid
          payment_history = {
              'amount_paid': self.amount_paid,
              'date_paid': self.date
             }
          return fee_balance
  </code></pre>
  <p>views.py</p>
  <pre><code>class FeeListView(LoginRequiredMixin, generic.ListView):
      model = FeeProfile
      context_object_name = 'fee_profile'
      template_name = 'fees/feeprofile_list.html'
      queryset = FeeProfile.objects.all()[:]'''
  </code></pre>