In Django simple app I have model Activity
Class Activity(models.Model):
class Meta:
verbose_name_plural = 'Activities'
date = models.DateField(verbose_name='Data')
start_time = models.TimeField(verbose_name='Czas rozpoczęcia')
end_time = models.TimeField(verbose_name='Czas zakończenia')
baby = models.ForeignKey(
Baby, on_delete=models.CASCADE, verbose_name='Dziecko', null=True, default=None, blank=False
)
In views.py i get all the activities from database and send it to activity_list.html page
def activity_list(request):
activity_list = Activity.objects.all().order_by('-date', '-start_time')
title='Lista aktywności'
return render(request, 'babybook/activity_list.html', locals())
There I can display all the data, but I would like to replace baby_id with the child’s first and last name.
In views, I have a method that changes my id to my first and last name
def getBabyName(id):
baby_name = Baby.objects.get(id=id)
return baby_name
But I don’t know how to pass the baby_name returned by the method instead of baby_id (or apart from baby_id) to the html page.
Thansk