title: How to create a custom function inside django model?
body: <p>I have a django model</p>
  
  <pre><code>class UserInfluencerGroupList(models.Model):
      list_name = models.CharField(max_length=255)
      influencers = models.ManyToManyField(Influencer, blank=True)
      user = models.ForeignKey(MyUser, on_delete = models.CASCADE)
  
      def __str__(self):
          return self.list_name
  </code></pre>
  
  <p>and my views function is:</p>
  
  <pre><code>def get_lists(request,user_email):
      """Get all the lists made by user"""
      try:
          user_instance = MyUser.objects.get(email=user_email)
      except MyUser.DoesNotExist:
          return HttpResponse(json.dumps({'message':'User not found'}),status=404)
  
      if request.method == 'GET':
  
          influencers_list = UserInfluencerGroupList.objects.all().order_by('id').filter(user=user_instance)
          influencers_list = serializers.serialize('json',influencers_list, fields =['id','influencers','list_name'], indent=2, use_natural_foreign_keys=True, use_natural_primary_keys=True)
  
          return HttpResponse(influencers_list,content_type='application/json',status=200)
      else:
          return HttpResponse(json.dumps({'message':'No lists found'}), status=400)
  
  </code></pre>
  
  <p>Apart from the usual data from list I also want to calculate the total_followers, total_likes and total_comments of each influencer in the list. The influencer model has fields for total_likes, comments and followers.</p>
  
  <p>How should I write a function to calculate and display it along with all the other data that the list is returning</p>