How to reverse fetch data in django models

I am working on a project and stuck somewhere to fetch the data child model which has a foreignkey of parent model.

this is how my model looks like

class Projects(models.Model):
    project_name = models.CharField(max_length=100,null=False)

class ProjectTask(models.Model):
    project_id = models.ForeignKey(Projects,on_delete=models.CASCADE,null=False)

class TaskBlockers(models.Model):
    task_id = models.ForeignKey(ProjectTask,on_delete=models.CASCADE,null=False,related_name='task_id_related')
    blocker = models.CharField(max_length=100,null=False)

now what I want is to get all the blockers under a projectTask which has a projectid = something.

ProjectTask.objects.filter(project_id=1) this will give a queryset right? and for each element in a queryset i want the blocker from TaskBlockers table.

can you tell me how we can achieve this?

Thanks for your help.

data = TaskBlockers.objects.filter(task_id__project_id_id=1).values("blocker")
Back to Top