i have three models : User, Campaign and Donation. Donation model has donation amount, donated by each user against each campaign.
Campaign model
class Campaign(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
campaign_title = models.CharField(max_length=200, blank=True)
Donation model
class Donation(models.Model):
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
# this is many to one relationship, on_deleting user, user's donation details will be set to NULL
campaign = models.ForeignKey(Campaign, on_delete=models.DO_NOTHING)
donation_amount = models.IntegerField()
views.py file
def landing_page(request):
# campaigns = Campaign.objects.all().order_by('-id')
campaigns = Campaign.objects.all().order_by('-id')
////DO SOMETHING HERE TO SHOW TOTAL DONATION AGAINST EACH CAMPAIGN////
return render(request, 'core/landing_page.html',{'campaigns':campaigns})
Using the current views.py file, I’m able to display all the campaigns, how do i pass the total donation against each campaign to the html file?