If I can have one more question (these are my first days with Python and Django)
I have three models:
class Guardian(models.Model):
guardian_first_name = models.CharField(max_length=50, verbose_name='Imię opiekuna')
guardian_last_name = models.CharField(max_length=100, verbose_name='Nazwisko opiekuna')
guardian_login = models.CharField(max_length=50, verbose_name='Login')
class Baby(models.Model):
class Meta:
verbose_name_plural = 'Babies'
first_name = models.CharField(max_length=50, verbose_name='Imię')
last_name = models.CharField(max_length=100, verbose_name='Nazwisko')
date_of_birth = models.DateField(verbose_name='Data urodzenia')
sex = models.CharField(max_length=12, verbose_name='Płeć')
height = models.PositiveIntegerField(verbose_name='Wzrost')
weight = models.DecimalField(verbose_name='Waga', decimal_places=2, max_digits=5)
guardian = models.ForeignKey(
Guardian, on_delete=models.CASCADE, verbose_name='Opiekun', null=True, default=None, blank=False)
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
)
activity_type = models.ForeignKey(
Activity_Type, on_delete=models.CASCADE, verbose_name='Rodzaj aktywności', blank=False, default=None, null=True
)
The Guardian object that is logged in has children who have their own activities. And I would like to download the activity list, but only his children. I have the guardian’s id so I download the list of his children
baby_list=Baby.objects.filter(guardian_id=guardianID)
I am also downloading a list of all Activities
activity_list = Activity.objects.all().order_by('-date', '-start_time')
How do I filter the queryset activity_list now so that it only leaves me there activities that are children from queryset baby_list?
Thank you